structs.go 45 KB

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