structs.go 26 KB

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