discord.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.Properties.OS = runtime.GOOS
  45. s.Identify.Properties.Browser = "DiscordGo v" + VERSION
  46. s.Identify.Intents = IntentsAllWithoutPrivileged
  47. s.Identify.Token = token
  48. s.Token = token
  49. return
  50. }