structs.go 46 KB

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