structs.go 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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. // The ID of the channel.
  155. ID string `json:"id"`
  156. // The ID of the guild to which the channel belongs, if it is in a guild.
  157. // Else, this ID is empty (e.g. DM channels).
  158. GuildID string `json:"guild_id"`
  159. // The name of the channel.
  160. Name string `json:"name"`
  161. // The topic of the channel.
  162. Topic string `json:"topic"`
  163. // The type of the channel.
  164. Type ChannelType `json:"type"`
  165. // The ID of the last message sent in the channel. This is not
  166. // guaranteed to be an ID of a valid message.
  167. LastMessageID string `json:"last_message_id"`
  168. // Whether the channel is marked as NSFW.
  169. NSFW bool `json:"nsfw"`
  170. // The position of the channel, used for sorting in client.
  171. Position int `json:"position"`
  172. // The bitrate of the channel, if it is a voice channel.
  173. Bitrate int `json:"bitrate"`
  174. // The recipients of the channel. This is only populated in DM channels.
  175. Recipients []*User `json:"recipients"`
  176. // The messages in the channel. This is only present in state-cached channels,
  177. // and State.MaxMessageCount must be non-zero.
  178. Messages []*Message `json:"-"`
  179. // A list of permission overwrites present for the channel.
  180. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  181. // The ID of the parent channel, if the channel is under a category
  182. ParentID string `json:"parent_id"`
  183. }
  184. // A ChannelEdit holds Channel Feild data for a channel edit.
  185. type ChannelEdit struct {
  186. Name string `json:"name,omitempty"`
  187. Topic string `json:"topic,omitempty"`
  188. NSFW bool `json:"nsfw,omitempty"`
  189. Position int `json:"position"`
  190. Bitrate int `json:"bitrate,omitempty"`
  191. UserLimit int `json:"user_limit,omitempty"`
  192. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  193. ParentID string `json:"parent_id,omitempty"`
  194. }
  195. // A PermissionOverwrite holds permission overwrite data for a Channel
  196. type PermissionOverwrite struct {
  197. ID string `json:"id"`
  198. Type string `json:"type"`
  199. Deny int `json:"deny"`
  200. Allow int `json:"allow"`
  201. }
  202. // Emoji struct holds data related to Emoji's
  203. type Emoji struct {
  204. ID string `json:"id"`
  205. Name string `json:"name"`
  206. Roles []string `json:"roles"`
  207. Managed bool `json:"managed"`
  208. RequireColons bool `json:"require_colons"`
  209. Animated bool `json:"animated"`
  210. }
  211. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  212. func (e *Emoji) APIName() string {
  213. if e.ID != "" && e.Name != "" {
  214. return e.Name + ":" + e.ID
  215. }
  216. if e.Name != "" {
  217. return e.Name
  218. }
  219. return e.ID
  220. }
  221. // VerificationLevel type definition
  222. type VerificationLevel int
  223. // Constants for VerificationLevel levels from 0 to 3 inclusive
  224. const (
  225. VerificationLevelNone VerificationLevel = iota
  226. VerificationLevelLow
  227. VerificationLevelMedium
  228. VerificationLevelHigh
  229. )
  230. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  231. // sometimes referred to as Servers in the Discord client.
  232. type Guild struct {
  233. // The ID of the guild.
  234. ID string `json:"id"`
  235. // The name of the guild. (2–100 characters)
  236. Name string `json:"name"`
  237. // The hash of the guild's icon. Use Session.GuildIcon
  238. // to retrieve the icon itself.
  239. Icon string `json:"icon"`
  240. // The voice region of the guild.
  241. Region string `json:"region"`
  242. // The ID of the AFK voice channel.
  243. AfkChannelID string `json:"afk_channel_id"`
  244. // The ID of the embed channel ID, used for embed widgets.
  245. EmbedChannelID string `json:"embed_channel_id"`
  246. // The user ID of the owner of the guild.
  247. OwnerID string `json:"owner_id"`
  248. // The time at which the current user joined the guild.
  249. // This field is only present in GUILD_CREATE events and websocket
  250. // update events, and thus is only present in state-cached guilds.
  251. JoinedAt Timestamp `json:"joined_at"`
  252. // The hash of the guild's splash.
  253. Splash string `json:"splash"`
  254. // The timeout, in seconds, before a user is considered AFK in voice.
  255. AfkTimeout int `json:"afk_timeout"`
  256. // The number of members in the guild.
  257. // This field is only present in GUILD_CREATE events and websocket
  258. // update events, and thus is only present in state-cached guilds.
  259. MemberCount int `json:"member_count"`
  260. // The verification level required for the guild.
  261. VerificationLevel VerificationLevel `json:"verification_level"`
  262. // Whether the guild has embedding enabled.
  263. EmbedEnabled bool `json:"embed_enabled"`
  264. // Whether the guild is considered large. This is
  265. // determined by a member threshold in the identify packet,
  266. // and is currently hard-coded at 250 members in the library.
  267. Large bool `json:"large"`
  268. // The default message notification setting for the guild.
  269. // 0 == all messages, 1 == mentions only.
  270. DefaultMessageNotifications int `json:"default_message_notifications"`
  271. // A list of roles in the guild.
  272. Roles []*Role `json:"roles"`
  273. // A list of the custom emojis present in the guild.
  274. Emojis []*Emoji `json:"emojis"`
  275. // A list of the members in the guild.
  276. // This field is only present in GUILD_CREATE events and websocket
  277. // update events, and thus is only present in state-cached guilds.
  278. Members []*Member `json:"members"`
  279. // A list of partial presence objects for members in the guild.
  280. // This field is only present in GUILD_CREATE events and websocket
  281. // update events, and thus is only present in state-cached guilds.
  282. Presences []*Presence `json:"presences"`
  283. // A list of channels in the guild.
  284. // This field is only present in GUILD_CREATE events and websocket
  285. // update events, and thus is only present in state-cached guilds.
  286. Channels []*Channel `json:"channels"`
  287. // A list of voice states for the guild.
  288. // This field is only present in GUILD_CREATE events and websocket
  289. // update events, and thus is only present in state-cached guilds.
  290. VoiceStates []*VoiceState `json:"voice_states"`
  291. // Whether this guild is currently unavailable (most likely due to outage).
  292. // This field is only present in GUILD_CREATE events and websocket
  293. // update events, and thus is only present in state-cached guilds.
  294. Unavailable bool `json:"unavailable"`
  295. }
  296. // A UserGuild holds a brief version of a Guild
  297. type UserGuild struct {
  298. ID string `json:"id"`
  299. Name string `json:"name"`
  300. Icon string `json:"icon"`
  301. Owner bool `json:"owner"`
  302. Permissions int `json:"permissions"`
  303. }
  304. // A GuildParams stores all the data needed to update discord guild settings
  305. type GuildParams struct {
  306. Name string `json:"name,omitempty"`
  307. Region string `json:"region,omitempty"`
  308. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  309. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  310. AfkChannelID string `json:"afk_channel_id,omitempty"`
  311. AfkTimeout int `json:"afk_timeout,omitempty"`
  312. Icon string `json:"icon,omitempty"`
  313. OwnerID string `json:"owner_id,omitempty"`
  314. Splash string `json:"splash,omitempty"`
  315. }
  316. // A Role stores information about Discord guild member roles.
  317. type Role struct {
  318. // The ID of the role.
  319. ID string `json:"id"`
  320. // The name of the role.
  321. Name string `json:"name"`
  322. // Whether this role is managed by an integration, and
  323. // thus cannot be manually added to, or taken from, members.
  324. Managed bool `json:"managed"`
  325. // Whether this role is mentionable.
  326. Mentionable bool `json:"mentionable"`
  327. // Whether this role is hoisted (shows up separately in member list).
  328. Hoist bool `json:"hoist"`
  329. // The hex color of this role.
  330. Color int `json:"color"`
  331. // The position of this role in the guild's role hierarchy.
  332. Position int `json:"position"`
  333. // The permissions of the role on the guild (doesn't include channel overrides).
  334. // This is a combination of bit masks; the presence of a certain permission can
  335. // be checked by performing a bitwise AND between this int and the permission.
  336. Permissions int `json:"permissions"`
  337. }
  338. // Mention returns a string which mentions the role
  339. func (r *Role) Mention() string {
  340. return fmt.Sprintf("<@&%s>", r.ID)
  341. }
  342. // Roles are a collection of Role
  343. type Roles []*Role
  344. func (r Roles) Len() int {
  345. return len(r)
  346. }
  347. func (r Roles) Less(i, j int) bool {
  348. return r[i].Position > r[j].Position
  349. }
  350. func (r Roles) Swap(i, j int) {
  351. r[i], r[j] = r[j], r[i]
  352. }
  353. // A VoiceState stores the voice states of Guilds
  354. type VoiceState struct {
  355. UserID string `json:"user_id"`
  356. SessionID string `json:"session_id"`
  357. ChannelID string `json:"channel_id"`
  358. GuildID string `json:"guild_id"`
  359. Suppress bool `json:"suppress"`
  360. SelfMute bool `json:"self_mute"`
  361. SelfDeaf bool `json:"self_deaf"`
  362. Mute bool `json:"mute"`
  363. Deaf bool `json:"deaf"`
  364. }
  365. // A Presence stores the online, offline, or idle and game status of Guild members.
  366. type Presence struct {
  367. User *User `json:"user"`
  368. Status Status `json:"status"`
  369. Game *Game `json:"game"`
  370. Nick string `json:"nick"`
  371. Roles []string `json:"roles"`
  372. Since *int `json:"since"`
  373. }
  374. // GameType is the type of "game" (see GameType* consts) in the Game struct
  375. type GameType int
  376. // Valid GameType values
  377. const (
  378. GameTypeGame GameType = iota
  379. GameTypeStreaming
  380. GameTypeListening
  381. GameTypeWatching
  382. )
  383. // A Game struct holds the name of the "playing .." game for a user
  384. type Game struct {
  385. Name string `json:"name"`
  386. Type GameType `json:"type"`
  387. URL string `json:"url,omitempty"`
  388. Details string `json:"details,omitempty"`
  389. State string `json:"state,omitempty"`
  390. TimeStamps TimeStamps `json:"timestamps,omitempty"`
  391. Assets Assets `json:"assets,omitempty"`
  392. ApplicationID string `json:"application_id,omitempty"`
  393. Instance int8 `json:"instance,omitempty"`
  394. // TODO: Party and Secrets (unknown structure)
  395. }
  396. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  397. type TimeStamps struct {
  398. EndTimestamp int64 `json:"end,omitempty"`
  399. StartTimestamp int64 `json:"start,omitempty"`
  400. }
  401. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  402. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  403. temp := struct {
  404. End float64 `json:"end,omitempty"`
  405. Start float64 `json:"start,omitempty"`
  406. }{}
  407. err := json.Unmarshal(b, &temp)
  408. if err != nil {
  409. return err
  410. }
  411. t.EndTimestamp = int64(temp.End)
  412. t.StartTimestamp = int64(temp.Start)
  413. return nil
  414. }
  415. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  416. type Assets struct {
  417. LargeImageID string `json:"large_image,omitempty"`
  418. SmallImageID string `json:"small_image,omitempty"`
  419. LargeText string `json:"large_text,omitempty"`
  420. SmallText string `json:"small_text,omitempty"`
  421. }
  422. // A Member stores user information for Guild members. A guild
  423. // member represents a certain user's presence in a guild.
  424. type Member struct {
  425. // The guild ID on which the member exists.
  426. GuildID string `json:"guild_id"`
  427. // The time at which the member joined the guild, in ISO8601.
  428. JoinedAt string `json:"joined_at"`
  429. // The nickname of the member, if they have one.
  430. Nick string `json:"nick"`
  431. // Whether the member is deafened at a guild level.
  432. Deaf bool `json:"deaf"`
  433. // Whether the member is muted at a guild level.
  434. Mute bool `json:"mute"`
  435. // The underlying user on which the member is based.
  436. User *User `json:"user"`
  437. // A list of IDs of the roles which are possessed by the member.
  438. Roles []string `json:"roles"`
  439. }
  440. // A Settings stores data for a specific users Discord client settings.
  441. type Settings struct {
  442. RenderEmbeds bool `json:"render_embeds"`
  443. InlineEmbedMedia bool `json:"inline_embed_media"`
  444. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  445. EnableTtsCommand bool `json:"enable_tts_command"`
  446. MessageDisplayCompact bool `json:"message_display_compact"`
  447. ShowCurrentGame bool `json:"show_current_game"`
  448. ConvertEmoticons bool `json:"convert_emoticons"`
  449. Locale string `json:"locale"`
  450. Theme string `json:"theme"`
  451. GuildPositions []string `json:"guild_positions"`
  452. RestrictedGuilds []string `json:"restricted_guilds"`
  453. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  454. Status Status `json:"status"`
  455. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  456. DeveloperMode bool `json:"developer_mode"`
  457. }
  458. // Status type definition
  459. type Status string
  460. // Constants for Status with the different current available status
  461. const (
  462. StatusOnline Status = "online"
  463. StatusIdle Status = "idle"
  464. StatusDoNotDisturb Status = "dnd"
  465. StatusInvisible Status = "invisible"
  466. StatusOffline Status = "offline"
  467. )
  468. // FriendSourceFlags stores ... TODO :)
  469. type FriendSourceFlags struct {
  470. All bool `json:"all"`
  471. MutualGuilds bool `json:"mutual_guilds"`
  472. MutualFriends bool `json:"mutual_friends"`
  473. }
  474. // A Relationship between the logged in user and Relationship.User
  475. type Relationship struct {
  476. User *User `json:"user"`
  477. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  478. ID string `json:"id"`
  479. }
  480. // A TooManyRequests struct holds information received from Discord
  481. // when receiving a HTTP 429 response.
  482. type TooManyRequests struct {
  483. Bucket string `json:"bucket"`
  484. Message string `json:"message"`
  485. RetryAfter time.Duration `json:"retry_after"`
  486. }
  487. // A ReadState stores data on the read state of channels.
  488. type ReadState struct {
  489. MentionCount int `json:"mention_count"`
  490. LastMessageID string `json:"last_message_id"`
  491. ID string `json:"id"`
  492. }
  493. // An Ack is used to ack messages
  494. type Ack struct {
  495. Token string `json:"token"`
  496. }
  497. // A GuildRole stores data for guild roles.
  498. type GuildRole struct {
  499. Role *Role `json:"role"`
  500. GuildID string `json:"guild_id"`
  501. }
  502. // A GuildBan stores data for a guild ban.
  503. type GuildBan struct {
  504. Reason string `json:"reason"`
  505. User *User `json:"user"`
  506. }
  507. // A GuildEmbed stores data for a guild embed.
  508. type GuildEmbed struct {
  509. Enabled bool `json:"enabled"`
  510. ChannelID string `json:"channel_id"`
  511. }
  512. // A GuildAuditLog stores data for a guild audit log.
  513. type GuildAuditLog struct {
  514. Webhooks []struct {
  515. ChannelID string `json:"channel_id"`
  516. GuildID string `json:"guild_id"`
  517. ID string `json:"id"`
  518. Avatar string `json:"avatar"`
  519. Name string `json:"name"`
  520. } `json:"webhooks,omitempty"`
  521. Users []struct {
  522. Username string `json:"username"`
  523. Discriminator string `json:"discriminator"`
  524. Bot bool `json:"bot"`
  525. ID string `json:"id"`
  526. Avatar string `json:"avatar"`
  527. } `json:"users,omitempty"`
  528. AuditLogEntries []struct {
  529. TargetID string `json:"target_id"`
  530. Changes []struct {
  531. NewValue interface{} `json:"new_value"`
  532. OldValue interface{} `json:"old_value"`
  533. Key string `json:"key"`
  534. } `json:"changes,omitempty"`
  535. UserID string `json:"user_id"`
  536. ID string `json:"id"`
  537. ActionType int `json:"action_type"`
  538. Options struct {
  539. DeleteMembersDay string `json:"delete_member_days"`
  540. MembersRemoved string `json:"members_removed"`
  541. ChannelID string `json:"channel_id"`
  542. Count string `json:"count"`
  543. ID string `json:"id"`
  544. Type string `json:"type"`
  545. RoleName string `json:"role_name"`
  546. } `json:"options,omitempty"`
  547. Reason string `json:"reason"`
  548. } `json:"audit_log_entries"`
  549. }
  550. // Block contains Discord Audit Log Action Types
  551. const (
  552. AuditLogActionGuildUpdate = 1
  553. AuditLogActionChannelCreate = 10
  554. AuditLogActionChannelUpdate = 11
  555. AuditLogActionChannelDelete = 12
  556. AuditLogActionChannelOverwriteCreate = 13
  557. AuditLogActionChannelOverwriteUpdate = 14
  558. AuditLogActionChannelOverwriteDelete = 15
  559. AuditLogActionMemberKick = 20
  560. AuditLogActionMemberPrune = 21
  561. AuditLogActionMemberBanAdd = 22
  562. AuditLogActionMemberBanRemove = 23
  563. AuditLogActionMemberUpdate = 24
  564. AuditLogActionMemberRoleUpdate = 25
  565. AuditLogActionRoleCreate = 30
  566. AuditLogActionRoleUpdate = 31
  567. AuditLogActionRoleDelete = 32
  568. AuditLogActionInviteCreate = 40
  569. AuditLogActionInviteUpdate = 41
  570. AuditLogActionInviteDelete = 42
  571. AuditLogActionWebhookCreate = 50
  572. AuditLogActionWebhookUpdate = 51
  573. AuditLogActionWebhookDelete = 52
  574. AuditLogActionEmojiCreate = 60
  575. AuditLogActionEmojiUpdate = 61
  576. AuditLogActionEmojiDelete = 62
  577. AuditLogActionMessageDelete = 72
  578. )
  579. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  580. type UserGuildSettingsChannelOverride struct {
  581. Muted bool `json:"muted"`
  582. MessageNotifications int `json:"message_notifications"`
  583. ChannelID string `json:"channel_id"`
  584. }
  585. // A UserGuildSettings stores data for a users guild settings.
  586. type UserGuildSettings struct {
  587. SupressEveryone bool `json:"suppress_everyone"`
  588. Muted bool `json:"muted"`
  589. MobilePush bool `json:"mobile_push"`
  590. MessageNotifications int `json:"message_notifications"`
  591. GuildID string `json:"guild_id"`
  592. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  593. }
  594. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  595. type UserGuildSettingsEdit struct {
  596. SupressEveryone bool `json:"suppress_everyone"`
  597. Muted bool `json:"muted"`
  598. MobilePush bool `json:"mobile_push"`
  599. MessageNotifications int `json:"message_notifications"`
  600. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  601. }
  602. // An APIErrorMessage is an api error message returned from discord
  603. type APIErrorMessage struct {
  604. Code int `json:"code"`
  605. Message string `json:"message"`
  606. }
  607. // Webhook stores the data for a webhook.
  608. type Webhook struct {
  609. ID string `json:"id"`
  610. GuildID string `json:"guild_id"`
  611. ChannelID string `json:"channel_id"`
  612. User *User `json:"user"`
  613. Name string `json:"name"`
  614. Avatar string `json:"avatar"`
  615. Token string `json:"token"`
  616. }
  617. // WebhookParams is a struct for webhook params, used in the WebhookExecute command.
  618. type WebhookParams struct {
  619. Content string `json:"content,omitempty"`
  620. Username string `json:"username,omitempty"`
  621. AvatarURL string `json:"avatar_url,omitempty"`
  622. TTS bool `json:"tts,omitempty"`
  623. File string `json:"file,omitempty"`
  624. Embeds []*MessageEmbed `json:"embeds,omitempty"`
  625. }
  626. // MessageReaction stores the data for a message reaction.
  627. type MessageReaction struct {
  628. UserID string `json:"user_id"`
  629. MessageID string `json:"message_id"`
  630. Emoji Emoji `json:"emoji"`
  631. ChannelID string `json:"channel_id"`
  632. }
  633. // GatewayBotResponse stores the data for the gateway/bot response
  634. type GatewayBotResponse struct {
  635. URL string `json:"url"`
  636. Shards int `json:"shards"`
  637. }
  638. // Constants for the different bit offsets of text channel permissions
  639. const (
  640. PermissionReadMessages = 1 << (iota + 10)
  641. PermissionSendMessages
  642. PermissionSendTTSMessages
  643. PermissionManageMessages
  644. PermissionEmbedLinks
  645. PermissionAttachFiles
  646. PermissionReadMessageHistory
  647. PermissionMentionEveryone
  648. PermissionUseExternalEmojis
  649. )
  650. // Constants for the different bit offsets of voice permissions
  651. const (
  652. PermissionVoiceConnect = 1 << (iota + 20)
  653. PermissionVoiceSpeak
  654. PermissionVoiceMuteMembers
  655. PermissionVoiceDeafenMembers
  656. PermissionVoiceMoveMembers
  657. PermissionVoiceUseVAD
  658. )
  659. // Constants for general management.
  660. const (
  661. PermissionChangeNickname = 1 << (iota + 26)
  662. PermissionManageNicknames
  663. PermissionManageRoles
  664. PermissionManageWebhooks
  665. PermissionManageEmojis
  666. )
  667. // Constants for the different bit offsets of general permissions
  668. const (
  669. PermissionCreateInstantInvite = 1 << iota
  670. PermissionKickMembers
  671. PermissionBanMembers
  672. PermissionAdministrator
  673. PermissionManageChannels
  674. PermissionManageServer
  675. PermissionAddReactions
  676. PermissionViewAuditLogs
  677. PermissionAllText = PermissionReadMessages |
  678. PermissionSendMessages |
  679. PermissionSendTTSMessages |
  680. PermissionManageMessages |
  681. PermissionEmbedLinks |
  682. PermissionAttachFiles |
  683. PermissionReadMessageHistory |
  684. PermissionMentionEveryone
  685. PermissionAllVoice = PermissionVoiceConnect |
  686. PermissionVoiceSpeak |
  687. PermissionVoiceMuteMembers |
  688. PermissionVoiceDeafenMembers |
  689. PermissionVoiceMoveMembers |
  690. PermissionVoiceUseVAD
  691. PermissionAllChannel = PermissionAllText |
  692. PermissionAllVoice |
  693. PermissionCreateInstantInvite |
  694. PermissionManageRoles |
  695. PermissionManageChannels |
  696. PermissionAddReactions |
  697. PermissionViewAuditLogs
  698. PermissionAll = PermissionAllChannel |
  699. PermissionKickMembers |
  700. PermissionBanMembers |
  701. PermissionManageServer |
  702. PermissionAdministrator
  703. )
  704. // Block contains Discord JSON Error Response codes
  705. const (
  706. ErrCodeUnknownAccount = 10001
  707. ErrCodeUnknownApplication = 10002
  708. ErrCodeUnknownChannel = 10003
  709. ErrCodeUnknownGuild = 10004
  710. ErrCodeUnknownIntegration = 10005
  711. ErrCodeUnknownInvite = 10006
  712. ErrCodeUnknownMember = 10007
  713. ErrCodeUnknownMessage = 10008
  714. ErrCodeUnknownOverwrite = 10009
  715. ErrCodeUnknownProvider = 10010
  716. ErrCodeUnknownRole = 10011
  717. ErrCodeUnknownToken = 10012
  718. ErrCodeUnknownUser = 10013
  719. ErrCodeUnknownEmoji = 10014
  720. ErrCodeBotsCannotUseEndpoint = 20001
  721. ErrCodeOnlyBotsCanUseEndpoint = 20002
  722. ErrCodeMaximumGuildsReached = 30001
  723. ErrCodeMaximumFriendsReached = 30002
  724. ErrCodeMaximumPinsReached = 30003
  725. ErrCodeMaximumGuildRolesReached = 30005
  726. ErrCodeTooManyReactions = 30010
  727. ErrCodeUnauthorized = 40001
  728. ErrCodeMissingAccess = 50001
  729. ErrCodeInvalidAccountType = 50002
  730. ErrCodeCannotExecuteActionOnDMChannel = 50003
  731. ErrCodeEmbedCisabled = 50004
  732. ErrCodeCannotEditFromAnotherUser = 50005
  733. ErrCodeCannotSendEmptyMessage = 50006
  734. ErrCodeCannotSendMessagesToThisUser = 50007
  735. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  736. ErrCodeChannelVerificationLevelTooHigh = 50009
  737. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  738. ErrCodeOAuth2ApplicationLimitReached = 50011
  739. ErrCodeInvalidOAuthState = 50012
  740. ErrCodeMissingPermissions = 50013
  741. ErrCodeInvalidAuthenticationToken = 50014
  742. ErrCodeNoteTooLong = 50015
  743. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  744. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  745. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  746. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  747. ErrCodeInvalidFormBody = 50035
  748. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  749. ErrCodeReactionBlocked = 90001
  750. )