session.go 688 B

12345678910111213141516171819202122232425262728
  1. package discordbot
  2. import "github.com/bwmarrin/discordgo"
  3. // GetSession - Get a discord session from the provided token
  4. func GetSession(token string) (*discordgo.Session, error) {
  5. session, err := discordgo.New("Bot " + token)
  6. // If we can not create the client then just fatal.
  7. if err != nil {
  8. return nil, err
  9. }
  10. session.Identify.Intents =
  11. discordgo.IntentsGuildMembers |
  12. discordgo.IntentsGuildVoiceStates |
  13. discordgo.IntentsGuildMessages |
  14. discordgo.IntentsDirectMessages |
  15. discordgo.IntentsDirectMessageReactions
  16. // Open a websocket connection to Discord and begin listening.
  17. err = session.Open()
  18. if err != nil {
  19. return nil, err
  20. }
  21. return session, nil
  22. }