discord.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. "errors"
  14. "fmt"
  15. "net/http"
  16. "runtime"
  17. "time"
  18. )
  19. // VERSION of DiscordGo, follows Semantic Versioning. (http://semver.org/)
  20. const VERSION = "0.23.0"
  21. // New creates a new Discord session with provided token.
  22. // If the token is for a bot, it must be prefixed with "Bot ".
  23. // e.g. "Bot ..."
  24. // Or if it is an OAuth2 token, it must be prefixed with "Bearer "
  25. // e.g. "Bearer ..."
  26. func New(token string) (s *Session, err error) {
  27. // Create an empty Session interface.
  28. s = &Session{
  29. State: NewState(),
  30. Ratelimiter: NewRatelimiter(),
  31. StateEnabled: true,
  32. Compress: true,
  33. ShouldReconnectOnError: true,
  34. ShardID: 0,
  35. ShardCount: 1,
  36. MaxRestRetries: 3,
  37. Client: &http.Client{Timeout: (20 * time.Second)},
  38. UserAgent: "DiscordBot (https://github.com/bwmarrin/discordgo, v" + VERSION + ")",
  39. sequence: new(int64),
  40. LastHeartbeatAck: time.Now().UTC(),
  41. }
  42. // Initilize the Identify Package with defaults
  43. // These can be modified prior to calling Open()
  44. s.Identify.Compress = true
  45. s.Identify.LargeThreshold = 250
  46. s.Identify.GuildSubscriptions = true
  47. s.Identify.Properties.OS = runtime.GOOS
  48. s.Identify.Properties.Browser = "DiscordGo v" + VERSION
  49. s.Identify.Intents = MakeIntent(IntentsAllWithoutPrivileged)
  50. s.Identify.Token = token
  51. s.Token = token
  52. return
  53. }