discord.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Discordgo - Discord bindings for Go
  2. // Available at https://github.com/bwmarrin/discordgo
  3. // Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
  4. // Use of this source code is governed by a BSD-style
  5. // license that can be found in the LICENSE file.
  6. // This file contains high level helper functions and easy entry points for the
  7. // entire discordgo package. These functions are being developed and are very
  8. // experimental at this point. They will most likely change so please use the
  9. // low level functions if that's a problem.
  10. // Package discordgo provides Discord binding for Go
  11. package discordgo
  12. import (
  13. "net/http"
  14. "runtime"
  15. "time"
  16. )
  17. // VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
  18. const VERSION = "0.24.0"
  19. // New creates a new Discord session with provided token.
  20. // If the token is for a bot, it must be prefixed with "Bot "
  21. // e.g. "Bot ..."
  22. // Or if it is an OAuth2 token, it must be prefixed with "Bearer "
  23. // e.g. "Bearer ..."
  24. func New(token string) (s *Session, err error) {
  25. // Create an empty Session interface.
  26. s = &Session{
  27. State: NewState(),
  28. Ratelimiter: NewRatelimiter(),
  29. StateEnabled: true,
  30. Compress: true,
  31. ShouldReconnectOnError: true,
  32. ShardID: 0,
  33. ShardCount: 1,
  34. MaxRestRetries: 3,
  35. Client: &http.Client{Timeout: (20 * time.Second)},
  36. UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
  37. sequence: new(int64),
  38. LastHeartbeatAck: time.Now().UTC(),
  39. }
  40. // Initilize the Identify Package with defaults
  41. // These can be modified prior to calling Open()
  42. s.Identify.Compress = true
  43. s.Identify.LargeThreshold = 250
  44. s.Identify.GuildSubscriptions = true
  45. s.Identify.Properties.OS = runtime.GOOS
  46. s.Identify.Properties.Browser = "DiscordGo v" + VERSION
  47. s.Identify.Intents = IntentsAllWithoutPrivileged
  48. s.Identify.Token = token
  49. s.Token = token
  50. return
  51. }