structs.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. "net/http"
  13. "sync"
  14. "time"
  15. "github.com/gorilla/websocket"
  16. )
  17. // A Session represents a connection to the Discord API.
  18. type Session struct {
  19. sync.RWMutex
  20. // General configurable settings.
  21. // Authentication token for this session
  22. Token string
  23. MFA bool
  24. // Debug for printing JSON request/responses
  25. Debug bool // Deprecated, will be removed.
  26. LogLevel int
  27. // Should the session reconnect the websocket on errors.
  28. ShouldReconnectOnError bool
  29. // Should the session request compressed websocket data.
  30. Compress bool
  31. // Sharding
  32. ShardID int
  33. ShardCount int
  34. // Should state tracking be enabled.
  35. // State tracking is the best way for getting the the users
  36. // active guilds and the members of the guilds.
  37. StateEnabled bool
  38. // Whether or not to call event handlers synchronously.
  39. // e.g false = launch event handlers in their own goroutines.
  40. SyncEvents bool
  41. // Exposed but should not be modified by User.
  42. // Whether the Data Websocket is ready
  43. DataReady bool // NOTE: Maye be deprecated soon
  44. // Max number of REST API retries
  45. MaxRestRetries int
  46. // Status stores the currect status of the websocket connection
  47. // this is being tested, may stay, may go away.
  48. status int32
  49. // Whether the Voice Websocket is ready
  50. VoiceReady bool // NOTE: Deprecated.
  51. // Whether the UDP Connection is ready
  52. UDPReady bool // NOTE: Deprecated
  53. // Stores a mapping of guild id's to VoiceConnections
  54. VoiceConnections map[string]*VoiceConnection
  55. // Managed state object, updated internally with events when
  56. // StateEnabled is true.
  57. State *State
  58. // The http client used for REST requests
  59. Client *http.Client
  60. // Stores the last HeartbeatAck that was recieved (in UTC)
  61. LastHeartbeatAck time.Time
  62. // used to deal with rate limits
  63. Ratelimiter *RateLimiter
  64. // Event handlers
  65. handlersMu sync.RWMutex
  66. handlers map[string][]*eventHandlerInstance
  67. onceHandlers map[string][]*eventHandlerInstance
  68. // The websocket connection.
  69. wsConn *websocket.Conn
  70. // When nil, the session is not listening.
  71. listening chan interface{}
  72. // sequence tracks the current gateway api websocket sequence number
  73. sequence *int64
  74. // stores sessions current Discord Gateway
  75. gateway string
  76. // stores session ID of current Gateway connection
  77. sessionID string
  78. // used to make sure gateway websocket writes do not happen concurrently
  79. wsMutex sync.Mutex
  80. }
  81. // A VoiceRegion stores data for a specific voice region server.
  82. type VoiceRegion struct {
  83. ID string `json:"id"`
  84. Name string `json:"name"`
  85. Hostname string `json:"sample_hostname"`
  86. Port int `json:"sample_port"`
  87. }
  88. // A VoiceICE stores data for voice ICE servers.
  89. type VoiceICE struct {
  90. TTL string `json:"ttl"`
  91. Servers []*ICEServer `json:"servers"`
  92. }
  93. // A ICEServer stores data for a specific voice ICE server.
  94. type ICEServer struct {
  95. URL string `json:"url"`
  96. Username string `json:"username"`
  97. Credential string `json:"credential"`
  98. }
  99. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  100. type Invite struct {
  101. Guild *Guild `json:"guild"`
  102. Channel *Channel `json:"channel"`
  103. Inviter *User `json:"inviter"`
  104. Code string `json:"code"`
  105. CreatedAt Timestamp `json:"created_at"`
  106. MaxAge int `json:"max_age"`
  107. Uses int `json:"uses"`
  108. MaxUses int `json:"max_uses"`
  109. Revoked bool `json:"revoked"`
  110. Temporary bool `json:"temporary"`
  111. Unique bool `json:"unique"`
  112. }
  113. // ChannelType is the type of a Channel
  114. type ChannelType int
  115. // Block contains known ChannelType values
  116. const (
  117. ChannelTypeGuildText ChannelType = iota
  118. ChannelTypeDM
  119. ChannelTypeGuildVoice
  120. ChannelTypeGroupDM
  121. ChannelTypeGuildCategory
  122. )
  123. // A Channel holds all data related to an individual Discord channel.
  124. type Channel struct {
  125. ID string `json:"id"`
  126. GuildID string `json:"guild_id"`
  127. Name string `json:"name"`
  128. Topic string `json:"topic"`
  129. Type ChannelType `json:"type"`
  130. LastMessageID string `json:"last_message_id"`
  131. NSFW bool `json:"nsfw"`
  132. Position int `json:"position"`
  133. Bitrate int `json:"bitrate"`
  134. Recipients []*User `json:"recipients"`
  135. Messages []*Message `json:"-"`
  136. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  137. ParentID string `json:"parent_id"`
  138. }
  139. // A ChannelEdit holds Channel Feild data for a channel edit.
  140. type ChannelEdit struct {
  141. Name string `json:"name,omitempty"`
  142. Topic string `json:"topic,omitempty"`
  143. NSFW bool `json:"nsfw,omitempty"`
  144. Position int `json:"position"`
  145. Bitrate int `json:"bitrate,omitempty"`
  146. UserLimit int `json:"user_limit,omitempty"`
  147. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  148. ParentID string `json:"parent_id,omitempty"`
  149. }
  150. // A PermissionOverwrite holds permission overwrite data for a Channel
  151. type PermissionOverwrite struct {
  152. ID string `json:"id"`
  153. Type string `json:"type"`
  154. Deny int `json:"deny"`
  155. Allow int `json:"allow"`
  156. }
  157. // Emoji struct holds data related to Emoji's
  158. type Emoji struct {
  159. ID string `json:"id"`
  160. Name string `json:"name"`
  161. Roles []string `json:"roles"`
  162. Managed bool `json:"managed"`
  163. RequireColons bool `json:"require_colons"`
  164. Animated bool `json:"animated"`
  165. }
  166. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  167. func (e *Emoji) APIName() string {
  168. if e.ID != "" && e.Name != "" {
  169. return e.Name + ":" + e.ID
  170. }
  171. if e.Name != "" {
  172. return e.Name
  173. }
  174. return e.ID
  175. }
  176. // VerificationLevel type definition
  177. type VerificationLevel int
  178. // Constants for VerificationLevel levels from 0 to 3 inclusive
  179. const (
  180. VerificationLevelNone VerificationLevel = iota
  181. VerificationLevelLow
  182. VerificationLevelMedium
  183. VerificationLevelHigh
  184. )
  185. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  186. // sometimes referred to as Servers in the Discord client.
  187. type Guild struct {
  188. ID string `json:"id"`
  189. Name string `json:"name"`
  190. Icon string `json:"icon"`
  191. Region string `json:"region"`
  192. AfkChannelID string `json:"afk_channel_id"`
  193. EmbedChannelID string `json:"embed_channel_id"`
  194. OwnerID string `json:"owner_id"`
  195. JoinedAt Timestamp `json:"joined_at"`
  196. Splash string `json:"splash"`
  197. AfkTimeout int `json:"afk_timeout"`
  198. MemberCount int `json:"member_count"`
  199. VerificationLevel VerificationLevel `json:"verification_level"`
  200. EmbedEnabled bool `json:"embed_enabled"`
  201. Large bool `json:"large"` // ??
  202. DefaultMessageNotifications int `json:"default_message_notifications"`
  203. Roles []*Role `json:"roles"`
  204. Emojis []*Emoji `json:"emojis"`
  205. Members []*Member `json:"members"`
  206. Presences []*Presence `json:"presences"`
  207. Channels []*Channel `json:"channels"`
  208. VoiceStates []*VoiceState `json:"voice_states"`
  209. Unavailable bool `json:"unavailable"`
  210. }
  211. // A UserGuild holds a brief version of a Guild
  212. type UserGuild struct {
  213. ID string `json:"id"`
  214. Name string `json:"name"`
  215. Icon string `json:"icon"`
  216. Owner bool `json:"owner"`
  217. Permissions int `json:"permissions"`
  218. }
  219. // A GuildParams stores all the data needed to update discord guild settings
  220. type GuildParams struct {
  221. Name string `json:"name,omitempty"`
  222. Region string `json:"region,omitempty"`
  223. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  224. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  225. AfkChannelID string `json:"afk_channel_id,omitempty"`
  226. AfkTimeout int `json:"afk_timeout,omitempty"`
  227. Icon string `json:"icon,omitempty"`
  228. OwnerID string `json:"owner_id,omitempty"`
  229. Splash string `json:"splash,omitempty"`
  230. }
  231. // A Role stores information about Discord guild member roles.
  232. type Role struct {
  233. ID string `json:"id"`
  234. Name string `json:"name"`
  235. Managed bool `json:"managed"`
  236. Mentionable bool `json:"mentionable"`
  237. Hoist bool `json:"hoist"`
  238. Color int `json:"color"`
  239. Position int `json:"position"`
  240. Permissions int `json:"permissions"`
  241. }
  242. // Roles are a collection of Role
  243. type Roles []*Role
  244. func (r Roles) Len() int {
  245. return len(r)
  246. }
  247. func (r Roles) Less(i, j int) bool {
  248. return r[i].Position > r[j].Position
  249. }
  250. func (r Roles) Swap(i, j int) {
  251. r[i], r[j] = r[j], r[i]
  252. }
  253. // A VoiceState stores the voice states of Guilds
  254. type VoiceState struct {
  255. UserID string `json:"user_id"`
  256. SessionID string `json:"session_id"`
  257. ChannelID string `json:"channel_id"`
  258. GuildID string `json:"guild_id"`
  259. Suppress bool `json:"suppress"`
  260. SelfMute bool `json:"self_mute"`
  261. SelfDeaf bool `json:"self_deaf"`
  262. Mute bool `json:"mute"`
  263. Deaf bool `json:"deaf"`
  264. }
  265. // A Presence stores the online, offline, or idle and game status of Guild members.
  266. type Presence struct {
  267. User *User `json:"user"`
  268. Status Status `json:"status"`
  269. Game *Game `json:"game"`
  270. Nick string `json:"nick"`
  271. Roles []string `json:"roles"`
  272. Since *int `json:"since"`
  273. }
  274. // GameType is the type of "game" (see GameType* consts) in the Game struct
  275. type GameType int
  276. // Valid GameType values
  277. const (
  278. GameTypeGame GameType = iota
  279. GameTypeStreaming
  280. GameTypeListening
  281. GameTypeWatching
  282. )
  283. // A Game struct holds the name of the "playing .." game for a user
  284. type Game struct {
  285. Name string `json:"name"`
  286. Type GameType `json:"type"`
  287. URL string `json:"url,omitempty"`
  288. Details string `json:"details,omitempty"`
  289. State string `json:"state,omitempty"`
  290. TimeStamps TimeStamps `json:"timestamps,omitempty"`
  291. Assets Assets `json:"assets,omitempty"`
  292. ApplicationID string `json:"application_id,omitempty"`
  293. Instance int8 `json:"instance,omitempty"`
  294. // TODO: Party and Secrets (unknown structure)
  295. }
  296. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  297. type TimeStamps struct {
  298. EndTimestamp int64 `json:"end,omitempty"`
  299. StartTimestamp int64 `json:"start,omitempty"`
  300. }
  301. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  302. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  303. temp := struct {
  304. End float64 `json:"end,omitempty"`
  305. Start float64 `json:"start,omitempty"`
  306. }{}
  307. err := json.Unmarshal(b, &temp)
  308. if err != nil {
  309. return err
  310. }
  311. t.EndTimestamp = int64(temp.End)
  312. t.StartTimestamp = int64(temp.Start)
  313. return nil
  314. }
  315. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  316. type Assets struct {
  317. LargeImageID string `json:"large_image,omitempty"`
  318. SmallImageID string `json:"small_image,omitempty"`
  319. LargeText string `json:"large_text,omitempty"`
  320. SmallText string `json:"small_text,omitempty"`
  321. }
  322. // A Member stores user information for Guild members.
  323. type Member struct {
  324. GuildID string `json:"guild_id"`
  325. JoinedAt string `json:"joined_at"`
  326. Nick string `json:"nick"`
  327. Deaf bool `json:"deaf"`
  328. Mute bool `json:"mute"`
  329. User *User `json:"user"`
  330. Roles []string `json:"roles"`
  331. }
  332. // A Settings stores data for a specific users Discord client settings.
  333. type Settings struct {
  334. RenderEmbeds bool `json:"render_embeds"`
  335. InlineEmbedMedia bool `json:"inline_embed_media"`
  336. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  337. EnableTtsCommand bool `json:"enable_tts_command"`
  338. MessageDisplayCompact bool `json:"message_display_compact"`
  339. ShowCurrentGame bool `json:"show_current_game"`
  340. ConvertEmoticons bool `json:"convert_emoticons"`
  341. Locale string `json:"locale"`
  342. Theme string `json:"theme"`
  343. GuildPositions []string `json:"guild_positions"`
  344. RestrictedGuilds []string `json:"restricted_guilds"`
  345. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  346. Status Status `json:"status"`
  347. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  348. DeveloperMode bool `json:"developer_mode"`
  349. }
  350. // Status type definition
  351. type Status string
  352. // Constants for Status with the different current available status
  353. const (
  354. StatusOnline Status = "online"
  355. StatusIdle Status = "idle"
  356. StatusDoNotDisturb Status = "dnd"
  357. StatusInvisible Status = "invisible"
  358. StatusOffline Status = "offline"
  359. )
  360. // FriendSourceFlags stores ... TODO :)
  361. type FriendSourceFlags struct {
  362. All bool `json:"all"`
  363. MutualGuilds bool `json:"mutual_guilds"`
  364. MutualFriends bool `json:"mutual_friends"`
  365. }
  366. // A Relationship between the logged in user and Relationship.User
  367. type Relationship struct {
  368. User *User `json:"user"`
  369. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  370. ID string `json:"id"`
  371. }
  372. // A TooManyRequests struct holds information received from Discord
  373. // when receiving a HTTP 429 response.
  374. type TooManyRequests struct {
  375. Bucket string `json:"bucket"`
  376. Message string `json:"message"`
  377. RetryAfter time.Duration `json:"retry_after"`
  378. }
  379. // A ReadState stores data on the read state of channels.
  380. type ReadState struct {
  381. MentionCount int `json:"mention_count"`
  382. LastMessageID string `json:"last_message_id"`
  383. ID string `json:"id"`
  384. }
  385. // An Ack is used to ack messages
  386. type Ack struct {
  387. Token string `json:"token"`
  388. }
  389. // A GuildRole stores data for guild roles.
  390. type GuildRole struct {
  391. Role *Role `json:"role"`
  392. GuildID string `json:"guild_id"`
  393. }
  394. // A GuildBan stores data for a guild ban.
  395. type GuildBan struct {
  396. Reason string `json:"reason"`
  397. User *User `json:"user"`
  398. }
  399. // A GuildIntegration stores data for a guild integration.
  400. type GuildIntegration struct {
  401. ID string `json:"id"`
  402. Name string `json:"name"`
  403. Type string `json:"type"`
  404. Enabled bool `json:"enabled"`
  405. Syncing bool `json:"syncing"`
  406. RoleID string `json:"role_id"`
  407. ExpireBehavior int `json:"expire_behavior"`
  408. ExpireGracePeriod int `json:"expire_grace_period"`
  409. User *User `json:"user"`
  410. Account *GuildIntegrationAccount `json:"account"`
  411. SyncedAt int `json:"synced_at"`
  412. }
  413. // A GuildIntegrationAccount stores data for a guild integration account.
  414. type GuildIntegrationAccount struct {
  415. ID string `json:"id"`
  416. Name string `json:"name"`
  417. }
  418. // A GuildEmbed stores data for a guild embed.
  419. type GuildEmbed struct {
  420. Enabled bool `json:"enabled"`
  421. ChannelID string `json:"channel_id"`
  422. }
  423. // A GuildAuditLog stores data for a guild audit log.
  424. type GuildAuditLog struct {
  425. Webhooks []struct {
  426. ChannelID string `json:"channel_id"`
  427. GuildID string `json:"guild_id"`
  428. ID string `json:"id"`
  429. Avatar string `json:"avatar"`
  430. Name string `json:"name"`
  431. } `json:"webhooks,omitempty"`
  432. Users []struct {
  433. Username string `json:"username"`
  434. Discriminator string `json:"discriminator"`
  435. Bot bool `json:"bot"`
  436. ID string `json:"id"`
  437. Avatar string `json:"avatar"`
  438. } `json:"users,omitempty"`
  439. AuditLogEntries []struct {
  440. TargetID string `json:"target_id"`
  441. Changes []struct {
  442. NewValue interface{} `json:"new_value"`
  443. OldValue interface{} `json:"old_value"`
  444. Key string `json:"key"`
  445. } `json:"changes,omitempty"`
  446. UserID string `json:"user_id"`
  447. ID string `json:"id"`
  448. ActionType int `json:"action_type"`
  449. Options struct {
  450. DeleteMembersDay string `json:"delete_member_days"`
  451. MembersRemoved string `json:"members_removed"`
  452. ChannelID string `json:"channel_id"`
  453. Count string `json:"count"`
  454. ID string `json:"id"`
  455. Type string `json:"type"`
  456. RoleName string `json:"role_name"`
  457. } `json:"options,omitempty"`
  458. Reason string `json:"reason"`
  459. } `json:"audit_log_entries"`
  460. }
  461. // Block contains Discord Audit Log Action Types
  462. const (
  463. AuditLogActionGuildUpdate = 1
  464. AuditLogActionChannelCreate = 10
  465. AuditLogActionChannelUpdate = 11
  466. AuditLogActionChannelDelete = 12
  467. AuditLogActionChannelOverwriteCreate = 13
  468. AuditLogActionChannelOverwriteUpdate = 14
  469. AuditLogActionChannelOverwriteDelete = 15
  470. AuditLogActionMemberKick = 20
  471. AuditLogActionMemberPrune = 21
  472. AuditLogActionMemberBanAdd = 22
  473. AuditLogActionMemberBanRemove = 23
  474. AuditLogActionMemberUpdate = 24
  475. AuditLogActionMemberRoleUpdate = 25
  476. AuditLogActionRoleCreate = 30
  477. AuditLogActionRoleUpdate = 31
  478. AuditLogActionRoleDelete = 32
  479. AuditLogActionInviteCreate = 40
  480. AuditLogActionInviteUpdate = 41
  481. AuditLogActionInviteDelete = 42
  482. AuditLogActionWebhookCreate = 50
  483. AuditLogActionWebhookUpdate = 51
  484. AuditLogActionWebhookDelete = 52
  485. AuditLogActionEmojiCreate = 60
  486. AuditLogActionEmojiUpdate = 61
  487. AuditLogActionEmojiDelete = 62
  488. AuditLogActionMessageDelete = 72
  489. )
  490. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  491. type UserGuildSettingsChannelOverride struct {
  492. Muted bool `json:"muted"`
  493. MessageNotifications int `json:"message_notifications"`
  494. ChannelID string `json:"channel_id"`
  495. }
  496. // A UserGuildSettings stores data for a users guild settings.
  497. type UserGuildSettings struct {
  498. SupressEveryone bool `json:"suppress_everyone"`
  499. Muted bool `json:"muted"`
  500. MobilePush bool `json:"mobile_push"`
  501. MessageNotifications int `json:"message_notifications"`
  502. GuildID string `json:"guild_id"`
  503. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  504. }
  505. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  506. type UserGuildSettingsEdit struct {
  507. SupressEveryone bool `json:"suppress_everyone"`
  508. Muted bool `json:"muted"`
  509. MobilePush bool `json:"mobile_push"`
  510. MessageNotifications int `json:"message_notifications"`
  511. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  512. }
  513. // An APIErrorMessage is an api error message returned from discord
  514. type APIErrorMessage struct {
  515. Code int `json:"code"`
  516. Message string `json:"message"`
  517. }
  518. // Webhook stores the data for a webhook.
  519. type Webhook struct {
  520. ID string `json:"id"`
  521. GuildID string `json:"guild_id"`
  522. ChannelID string `json:"channel_id"`
  523. User *User `json:"user"`
  524. Name string `json:"name"`
  525. Avatar string `json:"avatar"`
  526. Token string `json:"token"`
  527. }
  528. // WebhookParams is a struct for webhook params, used in the WebhookExecute command.
  529. type WebhookParams struct {
  530. Content string `json:"content,omitempty"`
  531. Username string `json:"username,omitempty"`
  532. AvatarURL string `json:"avatar_url,omitempty"`
  533. TTS bool `json:"tts,omitempty"`
  534. File string `json:"file,omitempty"`
  535. Embeds []*MessageEmbed `json:"embeds,omitempty"`
  536. }
  537. // MessageReaction stores the data for a message reaction.
  538. type MessageReaction struct {
  539. UserID string `json:"user_id"`
  540. MessageID string `json:"message_id"`
  541. Emoji Emoji `json:"emoji"`
  542. ChannelID string `json:"channel_id"`
  543. }
  544. // GatewayBotResponse stores the data for the gateway/bot response
  545. type GatewayBotResponse struct {
  546. URL string `json:"url"`
  547. Shards int `json:"shards"`
  548. }
  549. // Constants for the different bit offsets of text channel permissions
  550. const (
  551. PermissionReadMessages = 1 << (iota + 10)
  552. PermissionSendMessages
  553. PermissionSendTTSMessages
  554. PermissionManageMessages
  555. PermissionEmbedLinks
  556. PermissionAttachFiles
  557. PermissionReadMessageHistory
  558. PermissionMentionEveryone
  559. PermissionUseExternalEmojis
  560. )
  561. // Constants for the different bit offsets of voice permissions
  562. const (
  563. PermissionVoiceConnect = 1 << (iota + 20)
  564. PermissionVoiceSpeak
  565. PermissionVoiceMuteMembers
  566. PermissionVoiceDeafenMembers
  567. PermissionVoiceMoveMembers
  568. PermissionVoiceUseVAD
  569. )
  570. // Constants for general management.
  571. const (
  572. PermissionChangeNickname = 1 << (iota + 26)
  573. PermissionManageNicknames
  574. PermissionManageRoles
  575. PermissionManageWebhooks
  576. PermissionManageEmojis
  577. )
  578. // Constants for the different bit offsets of general permissions
  579. const (
  580. PermissionCreateInstantInvite = 1 << iota
  581. PermissionKickMembers
  582. PermissionBanMembers
  583. PermissionAdministrator
  584. PermissionManageChannels
  585. PermissionManageServer
  586. PermissionAddReactions
  587. PermissionViewAuditLogs
  588. PermissionAllText = PermissionReadMessages |
  589. PermissionSendMessages |
  590. PermissionSendTTSMessages |
  591. PermissionManageMessages |
  592. PermissionEmbedLinks |
  593. PermissionAttachFiles |
  594. PermissionReadMessageHistory |
  595. PermissionMentionEveryone
  596. PermissionAllVoice = PermissionVoiceConnect |
  597. PermissionVoiceSpeak |
  598. PermissionVoiceMuteMembers |
  599. PermissionVoiceDeafenMembers |
  600. PermissionVoiceMoveMembers |
  601. PermissionVoiceUseVAD
  602. PermissionAllChannel = PermissionAllText |
  603. PermissionAllVoice |
  604. PermissionCreateInstantInvite |
  605. PermissionManageRoles |
  606. PermissionManageChannels |
  607. PermissionAddReactions |
  608. PermissionViewAuditLogs
  609. PermissionAll = PermissionAllChannel |
  610. PermissionKickMembers |
  611. PermissionBanMembers |
  612. PermissionManageServer |
  613. PermissionAdministrator
  614. )
  615. // Block contains Discord JSON Error Response codes
  616. const (
  617. ErrCodeUnknownAccount = 10001
  618. ErrCodeUnknownApplication = 10002
  619. ErrCodeUnknownChannel = 10003
  620. ErrCodeUnknownGuild = 10004
  621. ErrCodeUnknownIntegration = 10005
  622. ErrCodeUnknownInvite = 10006
  623. ErrCodeUnknownMember = 10007
  624. ErrCodeUnknownMessage = 10008
  625. ErrCodeUnknownOverwrite = 10009
  626. ErrCodeUnknownProvider = 10010
  627. ErrCodeUnknownRole = 10011
  628. ErrCodeUnknownToken = 10012
  629. ErrCodeUnknownUser = 10013
  630. ErrCodeUnknownEmoji = 10014
  631. ErrCodeBotsCannotUseEndpoint = 20001
  632. ErrCodeOnlyBotsCanUseEndpoint = 20002
  633. ErrCodeMaximumGuildsReached = 30001
  634. ErrCodeMaximumFriendsReached = 30002
  635. ErrCodeMaximumPinsReached = 30003
  636. ErrCodeMaximumGuildRolesReached = 30005
  637. ErrCodeTooManyReactions = 30010
  638. ErrCodeUnauthorized = 40001
  639. ErrCodeMissingAccess = 50001
  640. ErrCodeInvalidAccountType = 50002
  641. ErrCodeCannotExecuteActionOnDMChannel = 50003
  642. ErrCodeEmbedCisabled = 50004
  643. ErrCodeCannotEditFromAnotherUser = 50005
  644. ErrCodeCannotSendEmptyMessage = 50006
  645. ErrCodeCannotSendMessagesToThisUser = 50007
  646. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  647. ErrCodeChannelVerificationLevelTooHigh = 50009
  648. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  649. ErrCodeOAuth2ApplicationLimitReached = 50011
  650. ErrCodeInvalidOAuthState = 50012
  651. ErrCodeMissingPermissions = 50013
  652. ErrCodeInvalidAuthenticationToken = 50014
  653. ErrCodeNoteTooLong = 50015
  654. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  655. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  656. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  657. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  658. ErrCodeInvalidFormBody = 50035
  659. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  660. ErrCodeReactionBlocked = 90001
  661. )