structs.go 45 KB

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