structs.go 46 KB

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