structs.go 25 KB

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