structs.go 46 KB

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