structs.go 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  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 all structures for the discordgo package. These
  7. // may be moved about later into separate files but I find it easier to have
  8. // them all located together.
  9. package discordgo
  10. import (
  11. "encoding/json"
  12. "fmt"
  13. "net/http"
  14. "strings"
  15. "sync"
  16. "time"
  17. "github.com/gorilla/websocket"
  18. )
  19. // A Session represents a connection to the Discord API.
  20. type Session struct {
  21. sync.RWMutex
  22. // General configurable settings.
  23. // Authentication token for this session
  24. // TODO: Remove Below, Deprecated, Use Identify struct
  25. Token string
  26. MFA bool
  27. // Debug for printing JSON request/responses
  28. Debug bool // Deprecated, will be removed.
  29. LogLevel int
  30. // Should the session reconnect the websocket on errors.
  31. ShouldReconnectOnError bool
  32. // Identify is sent during initial handshake with the discord gateway.
  33. // https://discord.com/developers/docs/topics/gateway#identify
  34. Identify Identify
  35. // TODO: Remove Below, Deprecated, Use Identify struct
  36. // Should the session request compressed websocket data.
  37. Compress bool
  38. // Sharding
  39. ShardID int
  40. ShardCount int
  41. // Should state tracking be enabled.
  42. // State tracking is the best way for getting the the users
  43. // active guilds and the members of the guilds.
  44. StateEnabled bool
  45. // Whether or not to call event handlers synchronously.
  46. // e.g false = launch event handlers in their own goroutines.
  47. SyncEvents bool
  48. // Exposed but should not be modified by User.
  49. // Whether the Data Websocket is ready
  50. DataReady bool // NOTE: Maye be deprecated soon
  51. // Max number of REST API retries
  52. MaxRestRetries int
  53. // Status stores the currect status of the websocket connection
  54. // this is being tested, may stay, may go away.
  55. status int32
  56. // Whether the Voice Websocket is ready
  57. VoiceReady bool // NOTE: Deprecated.
  58. // Whether the UDP Connection is ready
  59. UDPReady bool // NOTE: Deprecated
  60. // Stores a mapping of guild id's to VoiceConnections
  61. VoiceConnections map[string]*VoiceConnection
  62. // Managed state object, updated internally with events when
  63. // StateEnabled is true.
  64. State *State
  65. // The http client used for REST requests
  66. Client *http.Client
  67. // The user agent used for REST APIs
  68. UserAgent string
  69. // Stores the last HeartbeatAck that was recieved (in UTC)
  70. LastHeartbeatAck time.Time
  71. // Stores the last Heartbeat sent (in UTC)
  72. LastHeartbeatSent time.Time
  73. // used to deal with rate limits
  74. Ratelimiter *RateLimiter
  75. // Event handlers
  76. handlersMu sync.RWMutex
  77. handlers map[string][]*eventHandlerInstance
  78. onceHandlers map[string][]*eventHandlerInstance
  79. // The websocket connection.
  80. wsConn *websocket.Conn
  81. // When nil, the session is not listening.
  82. listening chan interface{}
  83. // sequence tracks the current gateway api websocket sequence number
  84. sequence *int64
  85. // stores sessions current Discord Gateway
  86. gateway string
  87. // stores session ID of current Gateway connection
  88. sessionID string
  89. // used to make sure gateway websocket writes do not happen concurrently
  90. wsMutex sync.Mutex
  91. }
  92. // UserConnection is a Connection returned from the UserConnections endpoint
  93. type UserConnection struct {
  94. ID string `json:"id"`
  95. Name string `json:"name"`
  96. Type string `json:"type"`
  97. Revoked bool `json:"revoked"`
  98. Integrations []*Integration `json:"integrations"`
  99. }
  100. // Integration stores integration information
  101. type Integration struct {
  102. ID string `json:"id"`
  103. Name string `json:"name"`
  104. Type string `json:"type"`
  105. Enabled bool `json:"enabled"`
  106. Syncing bool `json:"syncing"`
  107. RoleID string `json:"role_id"`
  108. EnableEmoticons bool `json:"enable_emoticons"`
  109. ExpireBehavior ExpireBehavior `json:"expire_behavior"`
  110. ExpireGracePeriod int `json:"expire_grace_period"`
  111. User *User `json:"user"`
  112. Account IntegrationAccount `json:"account"`
  113. SyncedAt Timestamp `json:"synced_at"`
  114. }
  115. //ExpireBehavior of Integration
  116. // https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
  117. type ExpireBehavior int
  118. // Block of valid ExpireBehaviors
  119. const (
  120. ExpireBehaviorRemoveRole ExpireBehavior = iota
  121. ExpireBehaviorKick
  122. )
  123. // IntegrationAccount is integration account information
  124. // sent by the UserConnections endpoint
  125. type IntegrationAccount struct {
  126. ID string `json:"id"`
  127. Name string `json:"name"`
  128. }
  129. // A VoiceRegion stores data for a specific voice region server.
  130. type VoiceRegion struct {
  131. ID string `json:"id"`
  132. Name string `json:"name"`
  133. Hostname string `json:"sample_hostname"`
  134. Port int `json:"sample_port"`
  135. }
  136. // A VoiceICE stores data for voice ICE servers.
  137. type VoiceICE struct {
  138. TTL string `json:"ttl"`
  139. Servers []*ICEServer `json:"servers"`
  140. }
  141. // A ICEServer stores data for a specific voice ICE server.
  142. type ICEServer struct {
  143. URL string `json:"url"`
  144. Username string `json:"username"`
  145. Credential string `json:"credential"`
  146. }
  147. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  148. type Invite struct {
  149. Guild *Guild `json:"guild"`
  150. Channel *Channel `json:"channel"`
  151. Inviter *User `json:"inviter"`
  152. Code string `json:"code"`
  153. CreatedAt Timestamp `json:"created_at"`
  154. MaxAge int `json:"max_age"`
  155. Uses int `json:"uses"`
  156. MaxUses int `json:"max_uses"`
  157. Revoked bool `json:"revoked"`
  158. Temporary bool `json:"temporary"`
  159. Unique bool `json:"unique"`
  160. TargetUser *User `json:"target_user"`
  161. TargetUserType TargetUserType `json:"target_user_type"`
  162. // will only be filled when using InviteWithCounts
  163. ApproximatePresenceCount int `json:"approximate_presence_count"`
  164. ApproximateMemberCount int `json:"approximate_member_count"`
  165. }
  166. // TargetUserType is the type of the target user
  167. // https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
  168. type TargetUserType int
  169. // Block contains known TargetUserType values
  170. const (
  171. TargetUserTypeStream TargetUserType = iota
  172. )
  173. // ChannelType is the type of a Channel
  174. type ChannelType int
  175. // Block contains known ChannelType values
  176. const (
  177. ChannelTypeGuildText ChannelType = iota
  178. ChannelTypeDM
  179. ChannelTypeGuildVoice
  180. ChannelTypeGroupDM
  181. ChannelTypeGuildCategory
  182. ChannelTypeGuildNews
  183. ChannelTypeGuildStore
  184. )
  185. // A Channel holds all data related to an individual Discord channel.
  186. type Channel struct {
  187. // The ID of the channel.
  188. ID string `json:"id"`
  189. // The ID of the guild to which the channel belongs, if it is in a guild.
  190. // Else, this ID is empty (e.g. DM channels).
  191. GuildID string `json:"guild_id"`
  192. // The name of the channel.
  193. Name string `json:"name"`
  194. // The topic of the channel.
  195. Topic string `json:"topic"`
  196. // The type of the channel.
  197. Type ChannelType `json:"type"`
  198. // The ID of the last message sent in the channel. This is not
  199. // guaranteed to be an ID of a valid message.
  200. LastMessageID string `json:"last_message_id"`
  201. // The timestamp of the last pinned message in the channel.
  202. // Empty if the channel has no pinned messages.
  203. LastPinTimestamp Timestamp `json:"last_pin_timestamp"`
  204. // Whether the channel is marked as NSFW.
  205. NSFW bool `json:"nsfw"`
  206. // Icon of the group DM channel.
  207. Icon string `json:"icon"`
  208. // The position of the channel, used for sorting in client.
  209. Position int `json:"position"`
  210. // The bitrate of the channel, if it is a voice channel.
  211. Bitrate int `json:"bitrate"`
  212. // The recipients of the channel. This is only populated in DM channels.
  213. Recipients []*User `json:"recipients"`
  214. // The messages in the channel. This is only present in state-cached channels,
  215. // and State.MaxMessageCount must be non-zero.
  216. Messages []*Message `json:"-"`
  217. // A list of permission overwrites present for the channel.
  218. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  219. // The user limit of the voice channel.
  220. UserLimit int `json:"user_limit"`
  221. // The ID of the parent channel, if the channel is under a category
  222. ParentID string `json:"parent_id"`
  223. // Amount of seconds a user has to wait before sending another message (0-21600)
  224. // bots, as well as users with the permission manage_messages or manage_channel, are unaffected
  225. RateLimitPerUser int `json:"rate_limit_per_user"`
  226. // ID of the DM creator Zeroed if guild channel
  227. OwnerID string `json:"owner_id"`
  228. // ApplicationID of the DM creator Zeroed if guild channel or not a bot user
  229. ApplicationID string `json:"application_id"`
  230. }
  231. // Mention returns a string which mentions the channel
  232. func (c *Channel) Mention() string {
  233. return fmt.Sprintf("<#%s>", c.ID)
  234. }
  235. // A ChannelEdit holds Channel Field data for a channel edit.
  236. type ChannelEdit struct {
  237. Name string `json:"name,omitempty"`
  238. Topic string `json:"topic,omitempty"`
  239. NSFW bool `json:"nsfw,omitempty"`
  240. Position int `json:"position"`
  241. Bitrate int `json:"bitrate,omitempty"`
  242. UserLimit int `json:"user_limit,omitempty"`
  243. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  244. ParentID string `json:"parent_id,omitempty"`
  245. RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
  246. }
  247. // A ChannelFollow holds data returned after following a news channel
  248. type ChannelFollow struct {
  249. ChannelID string `json:"channel_id"`
  250. WebhookID string `json:"webhook_id"`
  251. }
  252. // A PermissionOverwrite holds permission overwrite data for a Channel
  253. type PermissionOverwrite struct {
  254. ID string `json:"id"`
  255. Type string `json:"type"`
  256. Deny int `json:"deny"`
  257. Allow int `json:"allow"`
  258. }
  259. // Emoji struct holds data related to Emoji's
  260. type Emoji struct {
  261. ID string `json:"id"`
  262. Name string `json:"name"`
  263. Roles []string `json:"roles"`
  264. User *User `json:"user"`
  265. RequireColons bool `json:"require_colons"`
  266. Managed bool `json:"managed"`
  267. Animated bool `json:"animated"`
  268. Available bool `json:"available"`
  269. }
  270. // MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
  271. func (e *Emoji) MessageFormat() string {
  272. if e.ID != "" && e.Name != "" {
  273. if e.Animated {
  274. return "<a:" + e.APIName() + ">"
  275. }
  276. return "<:" + e.APIName() + ">"
  277. }
  278. return e.APIName()
  279. }
  280. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  281. func (e *Emoji) APIName() string {
  282. if e.ID != "" && e.Name != "" {
  283. return e.Name + ":" + e.ID
  284. }
  285. if e.Name != "" {
  286. return e.Name
  287. }
  288. return e.ID
  289. }
  290. // VerificationLevel type definition
  291. type VerificationLevel int
  292. // Constants for VerificationLevel levels from 0 to 4 inclusive
  293. const (
  294. VerificationLevelNone VerificationLevel = iota
  295. VerificationLevelLow
  296. VerificationLevelMedium
  297. VerificationLevelHigh
  298. VerificationLevelVeryHigh
  299. )
  300. // ExplicitContentFilterLevel type definition
  301. type ExplicitContentFilterLevel int
  302. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  303. const (
  304. ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
  305. ExplicitContentFilterMembersWithoutRoles
  306. ExplicitContentFilterAllMembers
  307. )
  308. // MfaLevel type definition
  309. type MfaLevel int
  310. // Constants for MfaLevel levels from 0 to 1 inclusive
  311. const (
  312. MfaLevelNone MfaLevel = iota
  313. MfaLevelElevated
  314. )
  315. // PremiumTier type definition
  316. type PremiumTier int
  317. // Constants for PremiumTier levels from 0 to 3 inclusive
  318. const (
  319. PremiumTierNone PremiumTier = iota
  320. PremiumTier1
  321. PremiumTier2
  322. PremiumTier3
  323. )
  324. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  325. // sometimes referred to as Servers in the Discord client.
  326. type Guild struct {
  327. // The ID of the guild.
  328. ID string `json:"id"`
  329. // The name of the guild. (2–100 characters)
  330. Name string `json:"name"`
  331. // The hash of the guild's icon. Use Session.GuildIcon
  332. // to retrieve the icon itself.
  333. Icon string `json:"icon"`
  334. // The voice region of the guild.
  335. Region string `json:"region"`
  336. // The ID of the AFK voice channel.
  337. AfkChannelID string `json:"afk_channel_id"`
  338. // The ID of the embed channel ID, used for embed widgets.
  339. EmbedChannelID string `json:"embed_channel_id"`
  340. // The user ID of the owner of the guild.
  341. OwnerID string `json:"owner_id"`
  342. // If we are the owner of the guild
  343. Owner bool `json:"owner"`
  344. // The time at which the current user joined the guild.
  345. // This field is only present in GUILD_CREATE events and websocket
  346. // update events, and thus is only present in state-cached guilds.
  347. JoinedAt Timestamp `json:"joined_at"`
  348. // The hash of the guild's discovery splash.
  349. DiscoverySplash string `json:"discovery_splash"`
  350. // The hash of the guild's splash.
  351. Splash string `json:"splash"`
  352. // The timeout, in seconds, before a user is considered AFK in voice.
  353. AfkTimeout int `json:"afk_timeout"`
  354. // The number of members in the guild.
  355. // This field is only present in GUILD_CREATE events and websocket
  356. // update events, and thus is only present in state-cached guilds.
  357. MemberCount int `json:"member_count"`
  358. // The verification level required for the guild.
  359. VerificationLevel VerificationLevel `json:"verification_level"`
  360. // Whether the guild has embedding enabled.
  361. EmbedEnabled bool `json:"embed_enabled"`
  362. // Whether the guild is considered large. This is
  363. // determined by a member threshold in the identify packet,
  364. // and is currently hard-coded at 250 members in the library.
  365. Large bool `json:"large"`
  366. // The default message notification setting for the guild.
  367. DefaultMessageNotifications MessageNotifications `json:"default_message_notifications"`
  368. // A list of roles in the guild.
  369. Roles []*Role `json:"roles"`
  370. // A list of the custom emojis present in the guild.
  371. Emojis []*Emoji `json:"emojis"`
  372. // A list of the members in the guild.
  373. // This field is only present in GUILD_CREATE events and websocket
  374. // update events, and thus is only present in state-cached guilds.
  375. Members []*Member `json:"members"`
  376. // A list of partial presence objects for members in the guild.
  377. // This field is only present in GUILD_CREATE events and websocket
  378. // update events, and thus is only present in state-cached guilds.
  379. Presences []*Presence `json:"presences"`
  380. // The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned)
  381. MaxPresences int `json:"max_presences"`
  382. // The maximum number of members for the guild
  383. MaxMembers int `json:"max_members"`
  384. // A list of channels in the guild.
  385. // This field is only present in GUILD_CREATE events and websocket
  386. // update events, and thus is only present in state-cached guilds.
  387. Channels []*Channel `json:"channels"`
  388. // A list of voice states for the guild.
  389. // This field is only present in GUILD_CREATE events and websocket
  390. // update events, and thus is only present in state-cached guilds.
  391. VoiceStates []*VoiceState `json:"voice_states"`
  392. // Whether this guild is currently unavailable (most likely due to outage).
  393. // This field is only present in GUILD_CREATE events and websocket
  394. // update events, and thus is only present in state-cached guilds.
  395. Unavailable bool `json:"unavailable"`
  396. // The explicit content filter level
  397. ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
  398. // The list of enabled guild features
  399. Features []string `json:"features"`
  400. // Required MFA level for the guild
  401. MfaLevel MfaLevel `json:"mfa_level"`
  402. // The application id of the guild if bot created.
  403. ApplicationID string `json:"application_id"`
  404. // Whether or not the Server Widget is enabled
  405. WidgetEnabled bool `json:"widget_enabled"`
  406. // The Channel ID for the Server Widget
  407. WidgetChannelID string `json:"widget_channel_id"`
  408. // The Channel ID to which system messages are sent (eg join and leave messages)
  409. SystemChannelID string `json:"system_channel_id"`
  410. // The System channel flags
  411. SystemChannelFlags SystemChannelFlag `json:"system_channel_flags"`
  412. // The ID of the rules channel ID, used for rules.
  413. RulesChannelID string `json:"rules_channel_id"`
  414. // the vanity url code for the guild
  415. VanityURLCode string `json:"vanity_url_code"`
  416. // the description for the guild
  417. Description string `json:"description"`
  418. // The hash of the guild's banner
  419. Banner string `json:"banner"`
  420. // The premium tier of the guild
  421. PremiumTier PremiumTier `json:"premium_tier"`
  422. // The total number of users currently boosting this server
  423. PremiumSubscriptionCount int `json:"premium_subscription_count"`
  424. // The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US"
  425. PreferredLocale string `json:"preferred_locale"`
  426. // The id of the channel where admins and moderators of guilds with the "PUBLIC" feature receive notices from Discord
  427. PublicUpdatesChannelID string `json:"public_updates_channel_id"`
  428. // The maximum amount of users in a video channel
  429. MaxVideoChannelUsers int `json:"max_video_channel_users"`
  430. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  431. ApproximateMemberCount int `json:"approximate_member_count"`
  432. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  433. ApproximatePresenceCount int `json:"approximate_presence_count"`
  434. // Permissions of our user
  435. Permissions int `json:"permissions"`
  436. }
  437. // MessageNotifications is the notification level for a guild
  438. // https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
  439. type MessageNotifications int
  440. // Block containing known MessageNotifications values
  441. const (
  442. MessageNotificationsAllMessages MessageNotifications = iota
  443. MessageNotificationsOnlyMentions
  444. )
  445. // SystemChannelFlag is the type of flags in the system channel (see SystemChannelFlag* consts)
  446. // https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags
  447. type SystemChannelFlag int
  448. // Block containing known SystemChannelFlag values
  449. const (
  450. SystemChannelFlagsSuppressJoin SystemChannelFlag = 1 << iota
  451. SystemChannelFlagsSuppressPremium
  452. )
  453. // IconURL returns a URL to the guild's icon.
  454. func (g *Guild) IconURL() string {
  455. if g.Icon == "" {
  456. return ""
  457. }
  458. if strings.HasPrefix(g.Icon, "a_") {
  459. return EndpointGuildIconAnimated(g.ID, g.Icon)
  460. }
  461. return EndpointGuildIcon(g.ID, g.Icon)
  462. }
  463. // A UserGuild holds a brief version of a Guild
  464. type UserGuild struct {
  465. ID string `json:"id"`
  466. Name string `json:"name"`
  467. Icon string `json:"icon"`
  468. Owner bool `json:"owner"`
  469. Permissions int `json:"permissions"`
  470. }
  471. // A GuildParams stores all the data needed to update discord guild settings
  472. type GuildParams struct {
  473. Name string `json:"name,omitempty"`
  474. Region string `json:"region,omitempty"`
  475. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  476. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  477. AfkChannelID string `json:"afk_channel_id,omitempty"`
  478. AfkTimeout int `json:"afk_timeout,omitempty"`
  479. Icon string `json:"icon,omitempty"`
  480. OwnerID string `json:"owner_id,omitempty"`
  481. Splash string `json:"splash,omitempty"`
  482. Banner string `json:"banner,omitempty"`
  483. }
  484. // A Role stores information about Discord guild member roles.
  485. type Role struct {
  486. // The ID of the role.
  487. ID string `json:"id"`
  488. // The name of the role.
  489. Name string `json:"name"`
  490. // Whether this role is managed by an integration, and
  491. // thus cannot be manually added to, or taken from, members.
  492. Managed bool `json:"managed"`
  493. // Whether this role is mentionable.
  494. Mentionable bool `json:"mentionable"`
  495. // Whether this role is hoisted (shows up separately in member list).
  496. Hoist bool `json:"hoist"`
  497. // The hex color of this role.
  498. Color int `json:"color"`
  499. // The position of this role in the guild's role hierarchy.
  500. Position int `json:"position"`
  501. // The permissions of the role on the guild (doesn't include channel overrides).
  502. // This is a combination of bit masks; the presence of a certain permission can
  503. // be checked by performing a bitwise AND between this int and the permission.
  504. Permissions int `json:"permissions"`
  505. }
  506. // Mention returns a string which mentions the role
  507. func (r *Role) Mention() string {
  508. return fmt.Sprintf("<@&%s>", r.ID)
  509. }
  510. // Roles are a collection of Role
  511. type Roles []*Role
  512. func (r Roles) Len() int {
  513. return len(r)
  514. }
  515. func (r Roles) Less(i, j int) bool {
  516. return r[i].Position > r[j].Position
  517. }
  518. func (r Roles) Swap(i, j int) {
  519. r[i], r[j] = r[j], r[i]
  520. }
  521. // A VoiceState stores the voice states of Guilds
  522. type VoiceState struct {
  523. UserID string `json:"user_id"`
  524. SessionID string `json:"session_id"`
  525. ChannelID string `json:"channel_id"`
  526. GuildID string `json:"guild_id"`
  527. Suppress bool `json:"suppress"`
  528. SelfMute bool `json:"self_mute"`
  529. SelfDeaf bool `json:"self_deaf"`
  530. Mute bool `json:"mute"`
  531. Deaf bool `json:"deaf"`
  532. }
  533. // A Presence stores the online, offline, or idle and game status of Guild members.
  534. type Presence struct {
  535. User *User `json:"user"`
  536. Status Status `json:"status"`
  537. Game *Game `json:"game"`
  538. Activities []*Game `json:"activities"`
  539. Nick string `json:"nick"`
  540. Roles []string `json:"roles"`
  541. Since *int `json:"since"`
  542. }
  543. // GameType is the type of "game" (see GameType* consts) in the Game struct
  544. type GameType int
  545. // Valid GameType values
  546. const (
  547. GameTypeGame GameType = iota
  548. GameTypeStreaming
  549. GameTypeListening
  550. GameTypeWatching
  551. GameTypeCustom
  552. )
  553. // A Game struct holds the name of the "playing .." game for a user
  554. type Game struct {
  555. Name string `json:"name"`
  556. Type GameType `json:"type"`
  557. URL string `json:"url,omitempty"`
  558. Details string `json:"details,omitempty"`
  559. State string `json:"state,omitempty"`
  560. TimeStamps TimeStamps `json:"timestamps,omitempty"`
  561. Assets Assets `json:"assets,omitempty"`
  562. ApplicationID string `json:"application_id,omitempty"`
  563. Instance int8 `json:"instance,omitempty"`
  564. // TODO: Party and Secrets (unknown structure)
  565. }
  566. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  567. type TimeStamps struct {
  568. EndTimestamp int64 `json:"end,omitempty"`
  569. StartTimestamp int64 `json:"start,omitempty"`
  570. }
  571. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  572. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  573. temp := struct {
  574. End float64 `json:"end,omitempty"`
  575. Start float64 `json:"start,omitempty"`
  576. }{}
  577. err := json.Unmarshal(b, &temp)
  578. if err != nil {
  579. return err
  580. }
  581. t.EndTimestamp = int64(temp.End)
  582. t.StartTimestamp = int64(temp.Start)
  583. return nil
  584. }
  585. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  586. type Assets struct {
  587. LargeImageID string `json:"large_image,omitempty"`
  588. SmallImageID string `json:"small_image,omitempty"`
  589. LargeText string `json:"large_text,omitempty"`
  590. SmallText string `json:"small_text,omitempty"`
  591. }
  592. // A Member stores user information for Guild members. A guild
  593. // member represents a certain user's presence in a guild.
  594. type Member struct {
  595. // The guild ID on which the member exists.
  596. GuildID string `json:"guild_id"`
  597. // The time at which the member joined the guild, in ISO8601.
  598. JoinedAt Timestamp `json:"joined_at"`
  599. // The nickname of the member, if they have one.
  600. Nick string `json:"nick"`
  601. // Whether the member is deafened at a guild level.
  602. Deaf bool `json:"deaf"`
  603. // Whether the member is muted at a guild level.
  604. Mute bool `json:"mute"`
  605. // The underlying user on which the member is based.
  606. User *User `json:"user"`
  607. // A list of IDs of the roles which are possessed by the member.
  608. Roles []string `json:"roles"`
  609. // When the user used their Nitro boost on the server
  610. PremiumSince Timestamp `json:"premium_since"`
  611. }
  612. // Mention creates a member mention
  613. func (m *Member) Mention() string {
  614. return "<@!" + m.User.ID + ">"
  615. }
  616. // A Settings stores data for a specific users Discord client settings.
  617. type Settings struct {
  618. RenderEmbeds bool `json:"render_embeds"`
  619. InlineEmbedMedia bool `json:"inline_embed_media"`
  620. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  621. EnableTTSCommand bool `json:"enable_tts_command"`
  622. MessageDisplayCompact bool `json:"message_display_compact"`
  623. ShowCurrentGame bool `json:"show_current_game"`
  624. ConvertEmoticons bool `json:"convert_emoticons"`
  625. Locale string `json:"locale"`
  626. Theme string `json:"theme"`
  627. GuildPositions []string `json:"guild_positions"`
  628. RestrictedGuilds []string `json:"restricted_guilds"`
  629. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  630. Status Status `json:"status"`
  631. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  632. DeveloperMode bool `json:"developer_mode"`
  633. }
  634. // Status type definition
  635. type Status string
  636. // Constants for Status with the different current available status
  637. const (
  638. StatusOnline Status = "online"
  639. StatusIdle Status = "idle"
  640. StatusDoNotDisturb Status = "dnd"
  641. StatusInvisible Status = "invisible"
  642. StatusOffline Status = "offline"
  643. )
  644. // FriendSourceFlags stores ... TODO :)
  645. type FriendSourceFlags struct {
  646. All bool `json:"all"`
  647. MutualGuilds bool `json:"mutual_guilds"`
  648. MutualFriends bool `json:"mutual_friends"`
  649. }
  650. // A Relationship between the logged in user and Relationship.User
  651. type Relationship struct {
  652. User *User `json:"user"`
  653. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  654. ID string `json:"id"`
  655. }
  656. // A TooManyRequests struct holds information received from Discord
  657. // when receiving a HTTP 429 response.
  658. type TooManyRequests struct {
  659. Bucket string `json:"bucket"`
  660. Message string `json:"message"`
  661. RetryAfter time.Duration `json:"retry_after"`
  662. }
  663. // A ReadState stores data on the read state of channels.
  664. type ReadState struct {
  665. MentionCount int `json:"mention_count"`
  666. LastMessageID string `json:"last_message_id"`
  667. ID string `json:"id"`
  668. }
  669. // An Ack is used to ack messages
  670. type Ack struct {
  671. Token string `json:"token"`
  672. }
  673. // A GuildRole stores data for guild roles.
  674. type GuildRole struct {
  675. Role *Role `json:"role"`
  676. GuildID string `json:"guild_id"`
  677. }
  678. // A GuildBan stores data for a guild ban.
  679. type GuildBan struct {
  680. Reason string `json:"reason"`
  681. User *User `json:"user"`
  682. }
  683. // A GuildEmbed stores data for a guild embed.
  684. type GuildEmbed struct {
  685. Enabled bool `json:"enabled"`
  686. ChannelID string `json:"channel_id"`
  687. }
  688. // A GuildAuditLog stores data for a guild audit log.
  689. // https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
  690. type GuildAuditLog struct {
  691. Webhooks []*Webhook `json:"webhooks,omitempty"`
  692. Users []*User `json:"users,omitempty"`
  693. AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
  694. Integrations []*Integration `json:"integrations"`
  695. }
  696. // AuditLogEntry for a GuildAuditLog
  697. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-entry-structure
  698. type AuditLogEntry struct {
  699. TargetID string `json:"target_id"`
  700. Changes []*AuditLogChange `json:"changes"`
  701. UserID string `json:"user_id"`
  702. ID string `json:"id"`
  703. ActionType *AuditLogAction `json:"action_type"`
  704. Options *AuditLogOptions `json:"options"`
  705. Reason string `json:"reason"`
  706. }
  707. // AuditLogChange for an AuditLogEntry
  708. type AuditLogChange struct {
  709. NewValue interface{} `json:"new_value"`
  710. OldValue interface{} `json:"old_value"`
  711. Key *AuditLogChangeKey `json:"key"`
  712. }
  713. // AuditLogChangeKey value for AuditLogChange
  714. // https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
  715. type AuditLogChangeKey string
  716. // Block of valid AuditLogChangeKey
  717. const (
  718. AuditLogChangeKeyName AuditLogChangeKey = "name"
  719. AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash"
  720. AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash"
  721. AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id"
  722. AuditLogChangeKeyRegion AuditLogChangeKey = "region"
  723. AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
  724. AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"
  725. AuditLogChangeKeyMfaLevel AuditLogChangeKey = "mfa_level"
  726. AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level"
  727. AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter"
  728. AuditLogChangeKeyDefaultMessageNotification AuditLogChangeKey = "default_message_notifications"
  729. AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code"
  730. AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add"
  731. AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove"
  732. AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
  733. AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled"
  734. AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id"
  735. AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id"
  736. AuditLogChangeKeyPosition AuditLogChangeKey = "position"
  737. AuditLogChangeKeyTopic AuditLogChangeKey = "topic"
  738. AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate"
  739. AuditLogChangeKeyPermissionOverwrite AuditLogChangeKey = "permission_overwrites"
  740. AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw"
  741. AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id"
  742. AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
  743. AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions"
  744. AuditLogChangeKeyColor AuditLogChangeKey = "color"
  745. AuditLogChangeKeyHoist AuditLogChangeKey = "hoist"
  746. AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable"
  747. AuditLogChangeKeyAllow AuditLogChangeKey = "allow"
  748. AuditLogChangeKeyDeny AuditLogChangeKey = "deny"
  749. AuditLogChangeKeyCode AuditLogChangeKey = "code"
  750. AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id"
  751. AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id"
  752. AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses"
  753. AuditLogChangeKeyUses AuditLogChangeKey = "uses"
  754. AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age"
  755. AuditLogChangeKeyTempoary AuditLogChangeKey = "temporary"
  756. AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf"
  757. AuditLogChangeKeyMute AuditLogChangeKey = "mute"
  758. AuditLogChangeKeyNick AuditLogChangeKey = "nick"
  759. AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash"
  760. AuditLogChangeKeyID AuditLogChangeKey = "id"
  761. AuditLogChangeKeyType AuditLogChangeKey = "type"
  762. AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons"
  763. AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior"
  764. AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
  765. )
  766. // AuditLogOptions optional data for the AuditLog
  767. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  768. type AuditLogOptions struct {
  769. DeleteMemberDays string `json:"delete_member_days"`
  770. MembersRemoved string `json:"members_removed"`
  771. ChannelID string `json:"channel_id"`
  772. MessageID string `json:"message_id"`
  773. Count string `json:"count"`
  774. ID string `json:"id"`
  775. Type *AuditLogOptionsType `json:"type"`
  776. RoleName string `json:"role_name"`
  777. }
  778. // AuditLogOptionsType of the AuditLogOption
  779. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  780. type AuditLogOptionsType string
  781. // Valid Types for AuditLogOptionsType
  782. const (
  783. AuditLogOptionsTypeMember AuditLogOptionsType = "member"
  784. AuditLogOptionsTypeRole AuditLogOptionsType = "role"
  785. )
  786. // AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
  787. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
  788. type AuditLogAction int
  789. // Block contains Discord Audit Log Action Types
  790. const (
  791. AuditLogActionGuildUpdate AuditLogAction = 1
  792. AuditLogActionChannelCreate AuditLogAction = 10
  793. AuditLogActionChannelUpdate AuditLogAction = 11
  794. AuditLogActionChannelDelete AuditLogAction = 12
  795. AuditLogActionChannelOverwriteCreate AuditLogAction = 13
  796. AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
  797. AuditLogActionChannelOverwriteDelete AuditLogAction = 15
  798. AuditLogActionMemberKick AuditLogAction = 20
  799. AuditLogActionMemberPrune AuditLogAction = 21
  800. AuditLogActionMemberBanAdd AuditLogAction = 22
  801. AuditLogActionMemberBanRemove AuditLogAction = 23
  802. AuditLogActionMemberUpdate AuditLogAction = 24
  803. AuditLogActionMemberRoleUpdate AuditLogAction = 25
  804. AuditLogActionRoleCreate AuditLogAction = 30
  805. AuditLogActionRoleUpdate AuditLogAction = 31
  806. AuditLogActionRoleDelete AuditLogAction = 32
  807. AuditLogActionInviteCreate AuditLogAction = 40
  808. AuditLogActionInviteUpdate AuditLogAction = 41
  809. AuditLogActionInviteDelete AuditLogAction = 42
  810. AuditLogActionWebhookCreate AuditLogAction = 50
  811. AuditLogActionWebhookUpdate AuditLogAction = 51
  812. AuditLogActionWebhookDelete AuditLogAction = 52
  813. AuditLogActionEmojiCreate AuditLogAction = 60
  814. AuditLogActionEmojiUpdate AuditLogAction = 61
  815. AuditLogActionEmojiDelete AuditLogAction = 62
  816. AuditLogActionMessageDelete AuditLogAction = 72
  817. AuditLogActionMessageBulkDelete AuditLogAction = 73
  818. AuditLogActionMessagePin AuditLogAction = 74
  819. AuditLogActionMessageUnpin AuditLogAction = 75
  820. AuditLogActionIntegrationCreate AuditLogAction = 80
  821. AuditLogActionIntegrationUpdate AuditLogAction = 81
  822. AuditLogActionIntegrationDelete AuditLogAction = 82
  823. )
  824. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  825. type UserGuildSettingsChannelOverride struct {
  826. Muted bool `json:"muted"`
  827. MessageNotifications int `json:"message_notifications"`
  828. ChannelID string `json:"channel_id"`
  829. }
  830. // A UserGuildSettings stores data for a users guild settings.
  831. type UserGuildSettings struct {
  832. SupressEveryone bool `json:"suppress_everyone"`
  833. Muted bool `json:"muted"`
  834. MobilePush bool `json:"mobile_push"`
  835. MessageNotifications int `json:"message_notifications"`
  836. GuildID string `json:"guild_id"`
  837. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  838. }
  839. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  840. type UserGuildSettingsEdit struct {
  841. SupressEveryone bool `json:"suppress_everyone"`
  842. Muted bool `json:"muted"`
  843. MobilePush bool `json:"mobile_push"`
  844. MessageNotifications int `json:"message_notifications"`
  845. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  846. }
  847. // An APIErrorMessage is an api error message returned from discord
  848. type APIErrorMessage struct {
  849. Code int `json:"code"`
  850. Message string `json:"message"`
  851. }
  852. // Webhook stores the data for a webhook.
  853. type Webhook struct {
  854. ID string `json:"id"`
  855. Type WebhookType `json:"type"`
  856. GuildID string `json:"guild_id"`
  857. ChannelID string `json:"channel_id"`
  858. User *User `json:"user"`
  859. Name string `json:"name"`
  860. Avatar string `json:"avatar"`
  861. Token string `json:"token"`
  862. // ApplicationID is the bot/OAuth2 application that created this webhook
  863. ApplicationID string `json:"application_id,omitempty"`
  864. }
  865. // WebhookType is the type of Webhook (see WebhookType* consts) in the Webhook struct
  866. // https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-types
  867. type WebhookType int
  868. // Valid WebhookType values
  869. const (
  870. WebhookTypeIncoming WebhookType = iota
  871. WebhookTypeChannelFollower
  872. )
  873. // WebhookParams is a struct for webhook params, used in the WebhookExecute command.
  874. type WebhookParams struct {
  875. Content string `json:"content,omitempty"`
  876. Username string `json:"username,omitempty"`
  877. AvatarURL string `json:"avatar_url,omitempty"`
  878. TTS bool `json:"tts,omitempty"`
  879. File string `json:"file,omitempty"`
  880. Embeds []*MessageEmbed `json:"embeds,omitempty"`
  881. AllowedMentions *MessageAllowedMentions `json:"allowed_mentions,omitempty"`
  882. }
  883. // MessageReaction stores the data for a message reaction.
  884. type MessageReaction struct {
  885. UserID string `json:"user_id"`
  886. MessageID string `json:"message_id"`
  887. Emoji Emoji `json:"emoji"`
  888. ChannelID string `json:"channel_id"`
  889. GuildID string `json:"guild_id,omitempty"`
  890. }
  891. // GatewayBotResponse stores the data for the gateway/bot response
  892. type GatewayBotResponse struct {
  893. URL string `json:"url"`
  894. Shards int `json:"shards"`
  895. }
  896. // GatewayStatusUpdate is sent by the client to indicate a presence or status update
  897. // https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  898. type GatewayStatusUpdate struct {
  899. Since int `json:"since"`
  900. Game Activity `json:"game"`
  901. Status string `json:"status"`
  902. AFK bool `json:"afk"`
  903. }
  904. // Activity defines the Activity sent with GatewayStatusUpdate
  905. // https://discord.com/developers/docs/topics/gateway#activity-object
  906. type Activity struct {
  907. Name string
  908. Type ActivityType
  909. URL string
  910. }
  911. // ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
  912. // https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
  913. type ActivityType int
  914. // Valid ActivityType values
  915. const (
  916. ActivityTypeGame GameType = iota
  917. ActivityTypeStreaming
  918. ActivityTypeListening
  919. // ActivityTypeWatching // not valid in this use case?
  920. ActivityTypeCustom = 4
  921. )
  922. // Identify is sent during initial handshake with the discord gateway.
  923. // https://discord.com/developers/docs/topics/gateway#identify
  924. type Identify struct {
  925. Token string `json:"token"`
  926. Properties IdentifyProperties `json:"properties"`
  927. Compress bool `json:"compress"`
  928. LargeThreshold int `json:"large_threshold"`
  929. Shard *[2]int `json:"shard,omitempty"`
  930. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  931. GuildSubscriptions bool `json:"guild_subscriptions"`
  932. Intents *Intent `json:"intents,omitempty"`
  933. }
  934. // IdentifyProperties contains the "properties" portion of an Identify packet
  935. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  936. type IdentifyProperties struct {
  937. OS string `json:"$os"`
  938. Browser string `json:"$browser"`
  939. Device string `json:"$device"`
  940. Referer string `json:"$referer"`
  941. ReferringDomain string `json:"$referring_domain"`
  942. }
  943. // Constants for the different bit offsets of text channel permissions
  944. const (
  945. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  946. PermissionReadMessages = 1 << (iota + 10)
  947. PermissionSendMessages
  948. PermissionSendTTSMessages
  949. PermissionManageMessages
  950. PermissionEmbedLinks
  951. PermissionAttachFiles
  952. PermissionReadMessageHistory
  953. PermissionMentionEveryone
  954. PermissionUseExternalEmojis
  955. )
  956. // Constants for the different bit offsets of voice permissions
  957. const (
  958. PermissionVoiceConnect = 1 << (iota + 20)
  959. PermissionVoiceSpeak
  960. PermissionVoiceMuteMembers
  961. PermissionVoiceDeafenMembers
  962. PermissionVoiceMoveMembers
  963. PermissionVoiceUseVAD
  964. PermissionVoicePrioritySpeaker = 1 << (iota + 2)
  965. )
  966. // Constants for general management.
  967. const (
  968. PermissionChangeNickname = 1 << (iota + 26)
  969. PermissionManageNicknames
  970. PermissionManageRoles
  971. PermissionManageWebhooks
  972. PermissionManageEmojis
  973. )
  974. // Constants for the different bit offsets of general permissions
  975. const (
  976. PermissionCreateInstantInvite = 1 << iota
  977. PermissionKickMembers
  978. PermissionBanMembers
  979. PermissionAdministrator
  980. PermissionManageChannels
  981. PermissionManageServer
  982. PermissionAddReactions
  983. PermissionViewAuditLogs
  984. PermissionViewChannel = 1 << (iota + 2)
  985. PermissionAllText = PermissionViewChannel |
  986. PermissionSendMessages |
  987. PermissionSendTTSMessages |
  988. PermissionManageMessages |
  989. PermissionEmbedLinks |
  990. PermissionAttachFiles |
  991. PermissionReadMessageHistory |
  992. PermissionMentionEveryone
  993. PermissionAllVoice = PermissionViewChannel |
  994. PermissionVoiceConnect |
  995. PermissionVoiceSpeak |
  996. PermissionVoiceMuteMembers |
  997. PermissionVoiceDeafenMembers |
  998. PermissionVoiceMoveMembers |
  999. PermissionVoiceUseVAD |
  1000. PermissionVoicePrioritySpeaker
  1001. PermissionAllChannel = PermissionAllText |
  1002. PermissionAllVoice |
  1003. PermissionCreateInstantInvite |
  1004. PermissionManageRoles |
  1005. PermissionManageChannels |
  1006. PermissionAddReactions |
  1007. PermissionViewAuditLogs
  1008. PermissionAll = PermissionAllChannel |
  1009. PermissionKickMembers |
  1010. PermissionBanMembers |
  1011. PermissionManageServer |
  1012. PermissionAdministrator |
  1013. PermissionManageWebhooks |
  1014. PermissionManageEmojis
  1015. )
  1016. // Block contains Discord JSON Error Response codes
  1017. const (
  1018. ErrCodeUnknownAccount = 10001
  1019. ErrCodeUnknownApplication = 10002
  1020. ErrCodeUnknownChannel = 10003
  1021. ErrCodeUnknownGuild = 10004
  1022. ErrCodeUnknownIntegration = 10005
  1023. ErrCodeUnknownInvite = 10006
  1024. ErrCodeUnknownMember = 10007
  1025. ErrCodeUnknownMessage = 10008
  1026. ErrCodeUnknownOverwrite = 10009
  1027. ErrCodeUnknownProvider = 10010
  1028. ErrCodeUnknownRole = 10011
  1029. ErrCodeUnknownToken = 10012
  1030. ErrCodeUnknownUser = 10013
  1031. ErrCodeUnknownEmoji = 10014
  1032. ErrCodeUnknownWebhook = 10015
  1033. ErrCodeUnknownBan = 10026
  1034. ErrCodeBotsCannotUseEndpoint = 20001
  1035. ErrCodeOnlyBotsCanUseEndpoint = 20002
  1036. ErrCodeMaximumGuildsReached = 30001
  1037. ErrCodeMaximumFriendsReached = 30002
  1038. ErrCodeMaximumPinsReached = 30003
  1039. ErrCodeMaximumGuildRolesReached = 30005
  1040. ErrCodeTooManyReactions = 30010
  1041. ErrCodeUnauthorized = 40001
  1042. ErrCodeMissingAccess = 50001
  1043. ErrCodeInvalidAccountType = 50002
  1044. ErrCodeCannotExecuteActionOnDMChannel = 50003
  1045. ErrCodeEmbedDisabled = 50004
  1046. ErrCodeCannotEditFromAnotherUser = 50005
  1047. ErrCodeCannotSendEmptyMessage = 50006
  1048. ErrCodeCannotSendMessagesToThisUser = 50007
  1049. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  1050. ErrCodeChannelVerificationLevelTooHigh = 50009
  1051. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  1052. ErrCodeOAuth2ApplicationLimitReached = 50011
  1053. ErrCodeInvalidOAuthState = 50012
  1054. ErrCodeMissingPermissions = 50013
  1055. ErrCodeInvalidAuthenticationToken = 50014
  1056. ErrCodeNoteTooLong = 50015
  1057. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  1058. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  1059. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  1060. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  1061. ErrCodeInvalidFormBody = 50035
  1062. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  1063. ErrCodeReactionBlocked = 90001
  1064. )
  1065. // Intent is the type of a Gateway Intent
  1066. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  1067. type Intent int
  1068. // Constants for the different bit offsets of intents
  1069. const (
  1070. IntentsGuilds Intent = 1 << iota
  1071. IntentsGuildMembers
  1072. IntentsGuildBans
  1073. IntentsGuildEmojis
  1074. IntentsGuildIntegrations
  1075. IntentsGuildWebhooks
  1076. IntentsGuildInvites
  1077. IntentsGuildVoiceStates
  1078. IntentsGuildPresences
  1079. IntentsGuildMessages
  1080. IntentsGuildMessageReactions
  1081. IntentsGuildMessageTyping
  1082. IntentsDirectMessages
  1083. IntentsDirectMessageReactions
  1084. IntentsDirectMessageTyping
  1085. IntentsAllWithoutPrivileged = IntentsGuilds |
  1086. IntentsGuildBans |
  1087. IntentsGuildEmojis |
  1088. IntentsGuildIntegrations |
  1089. IntentsGuildWebhooks |
  1090. IntentsGuildInvites |
  1091. IntentsGuildVoiceStates |
  1092. IntentsGuildMessages |
  1093. IntentsGuildMessageReactions |
  1094. IntentsGuildMessageTyping |
  1095. IntentsDirectMessages |
  1096. IntentsDirectMessageReactions |
  1097. IntentsDirectMessageTyping
  1098. IntentsAll = IntentsAllWithoutPrivileged |
  1099. IntentsGuildMembers |
  1100. IntentsGuildPresences
  1101. IntentsNone Intent = 0
  1102. )
  1103. // MakeIntent helps convert a gateway intent value for use in the Identify structure.
  1104. func MakeIntent(intents Intent) *Intent {
  1105. return &intents
  1106. }