structs.go 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337
  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. "math"
  14. "net/http"
  15. "strings"
  16. "sync"
  17. "time"
  18. "github.com/gorilla/websocket"
  19. )
  20. // A Session represents a connection to the Discord API.
  21. type Session struct {
  22. sync.RWMutex
  23. // General configurable settings.
  24. // Authentication token for this session
  25. // TODO: Remove Below, Deprecated, Use Identify struct
  26. Token string
  27. MFA bool
  28. // Debug for printing JSON request/responses
  29. Debug bool // Deprecated, will be removed.
  30. LogLevel int
  31. // Should the session reconnect the websocket on errors.
  32. ShouldReconnectOnError bool
  33. // Identify is sent during initial handshake with the discord gateway.
  34. // https://discord.com/developers/docs/topics/gateway#identify
  35. Identify Identify
  36. // TODO: Remove Below, Deprecated, Use Identify struct
  37. // Should the session request compressed websocket data.
  38. Compress bool
  39. // Sharding
  40. ShardID int
  41. ShardCount int
  42. // Should state tracking be enabled.
  43. // State tracking is the best way for getting the the users
  44. // active guilds and the members of the guilds.
  45. StateEnabled bool
  46. // Whether or not to call event handlers synchronously.
  47. // e.g false = launch event handlers in their own goroutines.
  48. SyncEvents bool
  49. // Exposed but should not be modified by User.
  50. // Whether the Data Websocket is ready
  51. DataReady bool // NOTE: Maye be deprecated soon
  52. // Max number of REST API retries
  53. MaxRestRetries int
  54. // Status stores the currect status of the websocket connection
  55. // this is being tested, may stay, may go away.
  56. status int32
  57. // Whether the Voice Websocket is ready
  58. VoiceReady bool // NOTE: Deprecated.
  59. // Whether the UDP Connection is ready
  60. UDPReady bool // NOTE: Deprecated
  61. // Stores a mapping of guild id's to VoiceConnections
  62. VoiceConnections map[string]*VoiceConnection
  63. // Managed state object, updated internally with events when
  64. // StateEnabled is true.
  65. State *State
  66. // The http client used for REST requests
  67. Client *http.Client
  68. // The user agent used for REST APIs
  69. UserAgent string
  70. // Stores the last HeartbeatAck that was recieved (in UTC)
  71. LastHeartbeatAck time.Time
  72. // Stores the last Heartbeat sent (in UTC)
  73. LastHeartbeatSent time.Time
  74. // used to deal with rate limits
  75. Ratelimiter *RateLimiter
  76. // Event handlers
  77. handlersMu sync.RWMutex
  78. handlers map[string][]*eventHandlerInstance
  79. onceHandlers map[string][]*eventHandlerInstance
  80. // The websocket connection.
  81. wsConn *websocket.Conn
  82. // When nil, the session is not listening.
  83. listening chan interface{}
  84. // sequence tracks the current gateway api websocket sequence number
  85. sequence *int64
  86. // stores sessions current Discord Gateway
  87. gateway string
  88. // stores session ID of current Gateway connection
  89. sessionID string
  90. // used to make sure gateway websocket writes do not happen concurrently
  91. wsMutex sync.Mutex
  92. }
  93. // UserConnection is a Connection returned from the UserConnections endpoint
  94. type UserConnection struct {
  95. ID string `json:"id"`
  96. Name string `json:"name"`
  97. Type string `json:"type"`
  98. Revoked bool `json:"revoked"`
  99. Integrations []*Integration `json:"integrations"`
  100. }
  101. // Integration stores integration information
  102. type Integration struct {
  103. ID string `json:"id"`
  104. Name string `json:"name"`
  105. Type string `json:"type"`
  106. Enabled bool `json:"enabled"`
  107. Syncing bool `json:"syncing"`
  108. RoleID string `json:"role_id"`
  109. EnableEmoticons bool `json:"enable_emoticons"`
  110. ExpireBehavior ExpireBehavior `json:"expire_behavior"`
  111. ExpireGracePeriod int `json:"expire_grace_period"`
  112. User *User `json:"user"`
  113. Account IntegrationAccount `json:"account"`
  114. SyncedAt Timestamp `json:"synced_at"`
  115. }
  116. // ExpireBehavior of Integration
  117. // https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
  118. type ExpireBehavior int
  119. // Block of valid ExpireBehaviors
  120. const (
  121. ExpireBehaviorRemoveRole ExpireBehavior = iota
  122. ExpireBehaviorKick
  123. )
  124. // IntegrationAccount is integration account information
  125. // sent by the UserConnections endpoint
  126. type IntegrationAccount struct {
  127. ID string `json:"id"`
  128. Name string `json:"name"`
  129. }
  130. // A VoiceRegion stores data for a specific voice region server.
  131. type VoiceRegion struct {
  132. ID string `json:"id"`
  133. Name string `json:"name"`
  134. Hostname string `json:"sample_hostname"`
  135. Port int `json:"sample_port"`
  136. }
  137. // A VoiceICE stores data for voice ICE servers.
  138. type VoiceICE struct {
  139. TTL string `json:"ttl"`
  140. Servers []*ICEServer `json:"servers"`
  141. }
  142. // A ICEServer stores data for a specific voice ICE server.
  143. type ICEServer struct {
  144. URL string `json:"url"`
  145. Username string `json:"username"`
  146. Credential string `json:"credential"`
  147. }
  148. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  149. type Invite struct {
  150. Guild *Guild `json:"guild"`
  151. Channel *Channel `json:"channel"`
  152. Inviter *User `json:"inviter"`
  153. Code string `json:"code"`
  154. CreatedAt Timestamp `json:"created_at"`
  155. MaxAge int `json:"max_age"`
  156. Uses int `json:"uses"`
  157. MaxUses int `json:"max_uses"`
  158. Revoked bool `json:"revoked"`
  159. Temporary bool `json:"temporary"`
  160. Unique bool `json:"unique"`
  161. TargetUser *User `json:"target_user"`
  162. TargetUserType TargetUserType `json:"target_user_type"`
  163. // will only be filled when using InviteWithCounts
  164. ApproximatePresenceCount int `json:"approximate_presence_count"`
  165. ApproximateMemberCount int `json:"approximate_member_count"`
  166. }
  167. // TargetUserType is the type of the target user
  168. // https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
  169. type TargetUserType int
  170. // Block contains known TargetUserType values
  171. const (
  172. TargetUserTypeStream TargetUserType = iota
  173. )
  174. // ChannelType is the type of a Channel
  175. type ChannelType int
  176. // Block contains known ChannelType values
  177. const (
  178. ChannelTypeGuildText ChannelType = iota
  179. ChannelTypeDM
  180. ChannelTypeGuildVoice
  181. ChannelTypeGroupDM
  182. ChannelTypeGuildCategory
  183. ChannelTypeGuildNews
  184. ChannelTypeGuildStore
  185. )
  186. // A Channel holds all data related to an individual Discord channel.
  187. type Channel struct {
  188. // The ID of the channel.
  189. ID string `json:"id"`
  190. // The ID of the guild to which the channel belongs, if it is in a guild.
  191. // Else, this ID is empty (e.g. DM channels).
  192. GuildID string `json:"guild_id"`
  193. // The name of the channel.
  194. Name string `json:"name"`
  195. // The topic of the channel.
  196. Topic string `json:"topic"`
  197. // The type of the channel.
  198. Type ChannelType `json:"type"`
  199. // The ID of the last message sent in the channel. This is not
  200. // guaranteed to be an ID of a valid message.
  201. LastMessageID string `json:"last_message_id"`
  202. // The timestamp of the last pinned message in the channel.
  203. // Empty if the channel has no pinned messages.
  204. LastPinTimestamp Timestamp `json:"last_pin_timestamp"`
  205. // Whether the channel is marked as NSFW.
  206. NSFW bool `json:"nsfw"`
  207. // Icon of the group DM channel.
  208. Icon string `json:"icon"`
  209. // The position of the channel, used for sorting in client.
  210. Position int `json:"position"`
  211. // The bitrate of the channel, if it is a voice channel.
  212. Bitrate int `json:"bitrate"`
  213. // The recipients of the channel. This is only populated in DM channels.
  214. Recipients []*User `json:"recipients"`
  215. // The messages in the channel. This is only present in state-cached channels,
  216. // and State.MaxMessageCount must be non-zero.
  217. Messages []*Message `json:"-"`
  218. // A list of permission overwrites present for the channel.
  219. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  220. // The user limit of the voice channel.
  221. UserLimit int `json:"user_limit"`
  222. // The ID of the parent channel, if the channel is under a category
  223. ParentID string `json:"parent_id"`
  224. // Amount of seconds a user has to wait before sending another message (0-21600)
  225. // bots, as well as users with the permission manage_messages or manage_channel, are unaffected
  226. RateLimitPerUser int `json:"rate_limit_per_user"`
  227. // ID of the DM creator Zeroed if guild channel
  228. OwnerID string `json:"owner_id"`
  229. // ApplicationID of the DM creator Zeroed if guild channel or not a bot user
  230. ApplicationID string `json:"application_id"`
  231. }
  232. // Mention returns a string which mentions the channel
  233. func (c *Channel) Mention() string {
  234. return fmt.Sprintf("<#%s>", c.ID)
  235. }
  236. // A ChannelEdit holds Channel Field data for a channel edit.
  237. type ChannelEdit struct {
  238. Name string `json:"name,omitempty"`
  239. Topic string `json:"topic,omitempty"`
  240. NSFW bool `json:"nsfw,omitempty"`
  241. Position int `json:"position"`
  242. Bitrate int `json:"bitrate,omitempty"`
  243. UserLimit int `json:"user_limit,omitempty"`
  244. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  245. ParentID string `json:"parent_id,omitempty"`
  246. RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
  247. }
  248. // A ChannelFollow holds data returned after following a news channel
  249. type ChannelFollow struct {
  250. ChannelID string `json:"channel_id"`
  251. WebhookID string `json:"webhook_id"`
  252. }
  253. // PermissionOverwriteType represents the type of resource on which
  254. // a permission overwrite acts.
  255. type PermissionOverwriteType int
  256. // The possible permission overwrite types.
  257. const (
  258. PermissionOverwriteTypeRole PermissionOverwriteType = iota
  259. PermissionOverwriteTypeMember
  260. )
  261. // A PermissionOverwrite holds permission overwrite data for a Channel
  262. type PermissionOverwrite struct {
  263. ID string `json:"id"`
  264. Type PermissionOverwriteType `json:"type"`
  265. Deny int64 `json:"deny,string"`
  266. Allow int64 `json:"allow,string"`
  267. }
  268. // Emoji struct holds data related to Emoji's
  269. type Emoji struct {
  270. ID string `json:"id"`
  271. Name string `json:"name"`
  272. Roles []string `json:"roles"`
  273. User *User `json:"user"`
  274. RequireColons bool `json:"require_colons"`
  275. Managed bool `json:"managed"`
  276. Animated bool `json:"animated"`
  277. Available bool `json:"available"`
  278. }
  279. // MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
  280. func (e *Emoji) MessageFormat() string {
  281. if e.ID != "" && e.Name != "" {
  282. if e.Animated {
  283. return "<a:" + e.APIName() + ">"
  284. }
  285. return "<:" + e.APIName() + ">"
  286. }
  287. return e.APIName()
  288. }
  289. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  290. func (e *Emoji) APIName() string {
  291. if e.ID != "" && e.Name != "" {
  292. return e.Name + ":" + e.ID
  293. }
  294. if e.Name != "" {
  295. return e.Name
  296. }
  297. return e.ID
  298. }
  299. // VerificationLevel type definition
  300. type VerificationLevel int
  301. // Constants for VerificationLevel levels from 0 to 4 inclusive
  302. const (
  303. VerificationLevelNone VerificationLevel = iota
  304. VerificationLevelLow
  305. VerificationLevelMedium
  306. VerificationLevelHigh
  307. VerificationLevelVeryHigh
  308. )
  309. // ExplicitContentFilterLevel type definition
  310. type ExplicitContentFilterLevel int
  311. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  312. const (
  313. ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
  314. ExplicitContentFilterMembersWithoutRoles
  315. ExplicitContentFilterAllMembers
  316. )
  317. // MfaLevel type definition
  318. type MfaLevel int
  319. // Constants for MfaLevel levels from 0 to 1 inclusive
  320. const (
  321. MfaLevelNone MfaLevel = iota
  322. MfaLevelElevated
  323. )
  324. // PremiumTier type definition
  325. type PremiumTier int
  326. // Constants for PremiumTier levels from 0 to 3 inclusive
  327. const (
  328. PremiumTierNone PremiumTier = iota
  329. PremiumTier1
  330. PremiumTier2
  331. PremiumTier3
  332. )
  333. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  334. // sometimes referred to as Servers in the Discord client.
  335. type Guild struct {
  336. // The ID of the guild.
  337. ID string `json:"id"`
  338. // The name of the guild. (2–100 characters)
  339. Name string `json:"name"`
  340. // The hash of the guild's icon. Use Session.GuildIcon
  341. // to retrieve the icon itself.
  342. Icon string `json:"icon"`
  343. // The voice region of the guild.
  344. Region string `json:"region"`
  345. // The ID of the AFK voice channel.
  346. AfkChannelID string `json:"afk_channel_id"`
  347. // The user ID of the owner of the guild.
  348. OwnerID string `json:"owner_id"`
  349. // If we are the owner of the guild
  350. Owner bool `json:"owner"`
  351. // The time at which the current user joined the guild.
  352. // This field is only present in GUILD_CREATE events and websocket
  353. // update events, and thus is only present in state-cached guilds.
  354. JoinedAt Timestamp `json:"joined_at"`
  355. // The hash of the guild's discovery splash.
  356. DiscoverySplash string `json:"discovery_splash"`
  357. // The hash of the guild's splash.
  358. Splash string `json:"splash"`
  359. // The timeout, in seconds, before a user is considered AFK in voice.
  360. AfkTimeout int `json:"afk_timeout"`
  361. // The number of members in the guild.
  362. // This field is only present in GUILD_CREATE events and websocket
  363. // update events, and thus is only present in state-cached guilds.
  364. MemberCount int `json:"member_count"`
  365. // The verification level required for the guild.
  366. VerificationLevel VerificationLevel `json:"verification_level"`
  367. // Whether the guild is considered large. This is
  368. // determined by a member threshold in the identify packet,
  369. // and is currently hard-coded at 250 members in the library.
  370. Large bool `json:"large"`
  371. // The default message notification setting for the guild.
  372. DefaultMessageNotifications MessageNotifications `json:"default_message_notifications"`
  373. // A list of roles in the guild.
  374. Roles []*Role `json:"roles"`
  375. // A list of the custom emojis present in the guild.
  376. Emojis []*Emoji `json:"emojis"`
  377. // A list of the members in the guild.
  378. // This field is only present in GUILD_CREATE events and websocket
  379. // update events, and thus is only present in state-cached guilds.
  380. Members []*Member `json:"members"`
  381. // A list of partial presence objects for members in the guild.
  382. // This field is only present in GUILD_CREATE events and websocket
  383. // update events, and thus is only present in state-cached guilds.
  384. Presences []*Presence `json:"presences"`
  385. // The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned)
  386. MaxPresences int `json:"max_presences"`
  387. // The maximum number of members for the guild
  388. MaxMembers int `json:"max_members"`
  389. // A list of channels in the guild.
  390. // This field is only present in GUILD_CREATE events and websocket
  391. // update events, and thus is only present in state-cached guilds.
  392. Channels []*Channel `json:"channels"`
  393. // A list of voice states for the guild.
  394. // This field is only present in GUILD_CREATE events and websocket
  395. // update events, and thus is only present in state-cached guilds.
  396. VoiceStates []*VoiceState `json:"voice_states"`
  397. // Whether this guild is currently unavailable (most likely due to outage).
  398. // This field is only present in GUILD_CREATE events and websocket
  399. // update events, and thus is only present in state-cached guilds.
  400. Unavailable bool `json:"unavailable"`
  401. // The explicit content filter level
  402. ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
  403. // The list of enabled guild features
  404. Features []string `json:"features"`
  405. // Required MFA level for the guild
  406. MfaLevel MfaLevel `json:"mfa_level"`
  407. // The application id of the guild if bot created.
  408. ApplicationID string `json:"application_id"`
  409. // Whether or not the Server Widget is enabled
  410. WidgetEnabled bool `json:"widget_enabled"`
  411. // The Channel ID for the Server Widget
  412. WidgetChannelID string `json:"widget_channel_id"`
  413. // The Channel ID to which system messages are sent (eg join and leave messages)
  414. SystemChannelID string `json:"system_channel_id"`
  415. // The System channel flags
  416. SystemChannelFlags SystemChannelFlag `json:"system_channel_flags"`
  417. // The ID of the rules channel ID, used for rules.
  418. RulesChannelID string `json:"rules_channel_id"`
  419. // the vanity url code for the guild
  420. VanityURLCode string `json:"vanity_url_code"`
  421. // the description for the guild
  422. Description string `json:"description"`
  423. // The hash of the guild's banner
  424. Banner string `json:"banner"`
  425. // The premium tier of the guild
  426. PremiumTier PremiumTier `json:"premium_tier"`
  427. // The total number of users currently boosting this server
  428. PremiumSubscriptionCount int `json:"premium_subscription_count"`
  429. // The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US"
  430. PreferredLocale string `json:"preferred_locale"`
  431. // The id of the channel where admins and moderators of guilds with the "PUBLIC" feature receive notices from Discord
  432. PublicUpdatesChannelID string `json:"public_updates_channel_id"`
  433. // The maximum amount of users in a video channel
  434. MaxVideoChannelUsers int `json:"max_video_channel_users"`
  435. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  436. ApproximateMemberCount int `json:"approximate_member_count"`
  437. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  438. ApproximatePresenceCount int `json:"approximate_presence_count"`
  439. // Permissions of our user
  440. Permissions int64 `json:"permissions,string"`
  441. }
  442. // A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild.
  443. type GuildPreview struct {
  444. // The ID of the guild.
  445. ID string `json:"id"`
  446. // The name of the guild. (2–100 characters)
  447. Name string `json:"name"`
  448. // The hash of the guild's icon. Use Session.GuildIcon
  449. // to retrieve the icon itself.
  450. Icon string `json:"icon"`
  451. // The hash of the guild's splash.
  452. Splash string `json:"splash"`
  453. // The hash of the guild's discovery splash.
  454. DiscoverySplash string `json:"discovery_splash"`
  455. // A list of the custom emojis present in the guild.
  456. Emojis []*Emoji `json:"emojis"`
  457. // The list of enabled guild features
  458. Features []string `json:"features"`
  459. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  460. ApproximateMemberCount int `json:"approximate_member_count"`
  461. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  462. ApproximatePresenceCount int `json:"approximate_presence_count"`
  463. // the description for the guild
  464. Description string `json:"description"`
  465. }
  466. // MessageNotifications is the notification level for a guild
  467. // https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
  468. type MessageNotifications int
  469. // Block containing known MessageNotifications values
  470. const (
  471. MessageNotificationsAllMessages MessageNotifications = iota
  472. MessageNotificationsOnlyMentions
  473. )
  474. // SystemChannelFlag is the type of flags in the system channel (see SystemChannelFlag* consts)
  475. // https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags
  476. type SystemChannelFlag int
  477. // Block containing known SystemChannelFlag values
  478. const (
  479. SystemChannelFlagsSuppressJoin SystemChannelFlag = 1 << iota
  480. SystemChannelFlagsSuppressPremium
  481. )
  482. // IconURL returns a URL to the guild's icon.
  483. func (g *Guild) IconURL() string {
  484. if g.Icon == "" {
  485. return ""
  486. }
  487. if strings.HasPrefix(g.Icon, "a_") {
  488. return EndpointGuildIconAnimated(g.ID, g.Icon)
  489. }
  490. return EndpointGuildIcon(g.ID, g.Icon)
  491. }
  492. // A UserGuild holds a brief version of a Guild
  493. type UserGuild struct {
  494. ID string `json:"id"`
  495. Name string `json:"name"`
  496. Icon string `json:"icon"`
  497. Owner bool `json:"owner"`
  498. Permissions int64 `json:"permissions,string"`
  499. }
  500. // A GuildParams stores all the data needed to update discord guild settings
  501. type GuildParams struct {
  502. Name string `json:"name,omitempty"`
  503. Region string `json:"region,omitempty"`
  504. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  505. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  506. AfkChannelID string `json:"afk_channel_id,omitempty"`
  507. AfkTimeout int `json:"afk_timeout,omitempty"`
  508. Icon string `json:"icon,omitempty"`
  509. OwnerID string `json:"owner_id,omitempty"`
  510. Splash string `json:"splash,omitempty"`
  511. Banner string `json:"banner,omitempty"`
  512. }
  513. // A Role stores information about Discord guild member roles.
  514. type Role struct {
  515. // The ID of the role.
  516. ID string `json:"id"`
  517. // The name of the role.
  518. Name string `json:"name"`
  519. // Whether this role is managed by an integration, and
  520. // thus cannot be manually added to, or taken from, members.
  521. Managed bool `json:"managed"`
  522. // Whether this role is mentionable.
  523. Mentionable bool `json:"mentionable"`
  524. // Whether this role is hoisted (shows up separately in member list).
  525. Hoist bool `json:"hoist"`
  526. // The hex color of this role.
  527. Color int `json:"color"`
  528. // The position of this role in the guild's role hierarchy.
  529. Position int `json:"position"`
  530. // The permissions of the role on the guild (doesn't include channel overrides).
  531. // This is a combination of bit masks; the presence of a certain permission can
  532. // be checked by performing a bitwise AND between this int and the permission.
  533. Permissions int64 `json:"permissions,string"`
  534. }
  535. // Mention returns a string which mentions the role
  536. func (r *Role) Mention() string {
  537. return fmt.Sprintf("<@&%s>", r.ID)
  538. }
  539. // Roles are a collection of Role
  540. type Roles []*Role
  541. func (r Roles) Len() int {
  542. return len(r)
  543. }
  544. func (r Roles) Less(i, j int) bool {
  545. return r[i].Position > r[j].Position
  546. }
  547. func (r Roles) Swap(i, j int) {
  548. r[i], r[j] = r[j], r[i]
  549. }
  550. // A VoiceState stores the voice states of Guilds
  551. type VoiceState struct {
  552. UserID string `json:"user_id"`
  553. SessionID string `json:"session_id"`
  554. ChannelID string `json:"channel_id"`
  555. GuildID string `json:"guild_id"`
  556. Suppress bool `json:"suppress"`
  557. SelfMute bool `json:"self_mute"`
  558. SelfDeaf bool `json:"self_deaf"`
  559. Mute bool `json:"mute"`
  560. Deaf bool `json:"deaf"`
  561. }
  562. // A Presence stores the online, offline, or idle and game status of Guild members.
  563. type Presence struct {
  564. User *User `json:"user"`
  565. Status Status `json:"status"`
  566. Activities []*Activity `json:"activities"`
  567. Since *int `json:"since"`
  568. }
  569. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  570. type TimeStamps struct {
  571. EndTimestamp int64 `json:"end,omitempty"`
  572. StartTimestamp int64 `json:"start,omitempty"`
  573. }
  574. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  575. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  576. temp := struct {
  577. End float64 `json:"end,omitempty"`
  578. Start float64 `json:"start,omitempty"`
  579. }{}
  580. err := json.Unmarshal(b, &temp)
  581. if err != nil {
  582. return err
  583. }
  584. t.EndTimestamp = int64(temp.End)
  585. t.StartTimestamp = int64(temp.Start)
  586. return nil
  587. }
  588. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  589. type Assets struct {
  590. LargeImageID string `json:"large_image,omitempty"`
  591. SmallImageID string `json:"small_image,omitempty"`
  592. LargeText string `json:"large_text,omitempty"`
  593. SmallText string `json:"small_text,omitempty"`
  594. }
  595. // A Member stores user information for Guild members. A guild
  596. // member represents a certain user's presence in a guild.
  597. type Member struct {
  598. // The guild ID on which the member exists.
  599. GuildID string `json:"guild_id"`
  600. // The time at which the member joined the guild, in ISO8601.
  601. JoinedAt Timestamp `json:"joined_at"`
  602. // The nickname of the member, if they have one.
  603. Nick string `json:"nick"`
  604. // Whether the member is deafened at a guild level.
  605. Deaf bool `json:"deaf"`
  606. // Whether the member is muted at a guild level.
  607. Mute bool `json:"mute"`
  608. // The underlying user on which the member is based.
  609. User *User `json:"user"`
  610. // A list of IDs of the roles which are possessed by the member.
  611. Roles []string `json:"roles"`
  612. // When the user used their Nitro boost on the server
  613. PremiumSince Timestamp `json:"premium_since"`
  614. // Is true while the member hasn't accepted the membership screen.
  615. Pending bool `json:"pending"`
  616. }
  617. // Mention creates a member mention
  618. func (m *Member) Mention() string {
  619. return "<@!" + m.User.ID + ">"
  620. }
  621. // A Settings stores data for a specific users Discord client settings.
  622. type Settings struct {
  623. RenderEmbeds bool `json:"render_embeds"`
  624. InlineEmbedMedia bool `json:"inline_embed_media"`
  625. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  626. EnableTTSCommand bool `json:"enable_tts_command"`
  627. MessageDisplayCompact bool `json:"message_display_compact"`
  628. ShowCurrentGame bool `json:"show_current_game"`
  629. ConvertEmoticons bool `json:"convert_emoticons"`
  630. Locale string `json:"locale"`
  631. Theme string `json:"theme"`
  632. GuildPositions []string `json:"guild_positions"`
  633. RestrictedGuilds []string `json:"restricted_guilds"`
  634. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  635. Status Status `json:"status"`
  636. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  637. DeveloperMode bool `json:"developer_mode"`
  638. }
  639. // Status type definition
  640. type Status string
  641. // Constants for Status with the different current available status
  642. const (
  643. StatusOnline Status = "online"
  644. StatusIdle Status = "idle"
  645. StatusDoNotDisturb Status = "dnd"
  646. StatusInvisible Status = "invisible"
  647. StatusOffline Status = "offline"
  648. )
  649. // FriendSourceFlags stores ... TODO :)
  650. type FriendSourceFlags struct {
  651. All bool `json:"all"`
  652. MutualGuilds bool `json:"mutual_guilds"`
  653. MutualFriends bool `json:"mutual_friends"`
  654. }
  655. // A Relationship between the logged in user and Relationship.User
  656. type Relationship struct {
  657. User *User `json:"user"`
  658. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  659. ID string `json:"id"`
  660. }
  661. // A TooManyRequests struct holds information received from Discord
  662. // when receiving a HTTP 429 response.
  663. type TooManyRequests struct {
  664. Bucket string `json:"bucket"`
  665. Message string `json:"message"`
  666. RetryAfter time.Duration `json:"retry_after"`
  667. }
  668. // UnmarshalJSON helps support translation of a milliseconds-based float
  669. // into a time.Duration on TooManyRequests.
  670. func (t *TooManyRequests) UnmarshalJSON(b []byte) error {
  671. u := struct {
  672. Bucket string `json:"bucket"`
  673. Message string `json:"message"`
  674. RetryAfter float64 `json:"retry_after"`
  675. }{}
  676. err := json.Unmarshal(b, &u)
  677. if err != nil {
  678. return err
  679. }
  680. t.Bucket = u.Bucket
  681. t.Message = u.Message
  682. whole, frac := math.Modf(u.RetryAfter)
  683. t.RetryAfter = time.Duration(whole)*time.Second + time.Duration(frac*1000)*time.Millisecond
  684. return nil
  685. }
  686. // A ReadState stores data on the read state of channels.
  687. type ReadState struct {
  688. MentionCount int `json:"mention_count"`
  689. LastMessageID string `json:"last_message_id"`
  690. ID string `json:"id"`
  691. }
  692. // An Ack is used to ack messages
  693. type Ack struct {
  694. Token string `json:"token"`
  695. }
  696. // A GuildRole stores data for guild roles.
  697. type GuildRole struct {
  698. Role *Role `json:"role"`
  699. GuildID string `json:"guild_id"`
  700. }
  701. // A GuildBan stores data for a guild ban.
  702. type GuildBan struct {
  703. Reason string `json:"reason"`
  704. User *User `json:"user"`
  705. }
  706. // A GuildEmbed stores data for a guild embed.
  707. type GuildEmbed struct {
  708. Enabled bool `json:"enabled"`
  709. ChannelID string `json:"channel_id"`
  710. }
  711. // A GuildAuditLog stores data for a guild audit log.
  712. // https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
  713. type GuildAuditLog struct {
  714. Webhooks []*Webhook `json:"webhooks,omitempty"`
  715. Users []*User `json:"users,omitempty"`
  716. AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
  717. Integrations []*Integration `json:"integrations"`
  718. }
  719. // AuditLogEntry for a GuildAuditLog
  720. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-entry-structure
  721. type AuditLogEntry struct {
  722. TargetID string `json:"target_id"`
  723. Changes []*AuditLogChange `json:"changes"`
  724. UserID string `json:"user_id"`
  725. ID string `json:"id"`
  726. ActionType *AuditLogAction `json:"action_type"`
  727. Options *AuditLogOptions `json:"options"`
  728. Reason string `json:"reason"`
  729. }
  730. // AuditLogChange for an AuditLogEntry
  731. type AuditLogChange struct {
  732. NewValue interface{} `json:"new_value"`
  733. OldValue interface{} `json:"old_value"`
  734. Key *AuditLogChangeKey `json:"key"`
  735. }
  736. // AuditLogChangeKey value for AuditLogChange
  737. // https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
  738. type AuditLogChangeKey string
  739. // Block of valid AuditLogChangeKey
  740. const (
  741. AuditLogChangeKeyName AuditLogChangeKey = "name"
  742. AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash"
  743. AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash"
  744. AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id"
  745. AuditLogChangeKeyRegion AuditLogChangeKey = "region"
  746. AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
  747. AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"
  748. AuditLogChangeKeyMfaLevel AuditLogChangeKey = "mfa_level"
  749. AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level"
  750. AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter"
  751. AuditLogChangeKeyDefaultMessageNotification AuditLogChangeKey = "default_message_notifications"
  752. AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code"
  753. AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add"
  754. AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove"
  755. AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
  756. AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled"
  757. AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id"
  758. AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id"
  759. AuditLogChangeKeyPosition AuditLogChangeKey = "position"
  760. AuditLogChangeKeyTopic AuditLogChangeKey = "topic"
  761. AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate"
  762. AuditLogChangeKeyPermissionOverwrite AuditLogChangeKey = "permission_overwrites"
  763. AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw"
  764. AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id"
  765. AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
  766. AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions"
  767. AuditLogChangeKeyColor AuditLogChangeKey = "color"
  768. AuditLogChangeKeyHoist AuditLogChangeKey = "hoist"
  769. AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable"
  770. AuditLogChangeKeyAllow AuditLogChangeKey = "allow"
  771. AuditLogChangeKeyDeny AuditLogChangeKey = "deny"
  772. AuditLogChangeKeyCode AuditLogChangeKey = "code"
  773. AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id"
  774. AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id"
  775. AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses"
  776. AuditLogChangeKeyUses AuditLogChangeKey = "uses"
  777. AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age"
  778. AuditLogChangeKeyTempoary AuditLogChangeKey = "temporary"
  779. AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf"
  780. AuditLogChangeKeyMute AuditLogChangeKey = "mute"
  781. AuditLogChangeKeyNick AuditLogChangeKey = "nick"
  782. AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash"
  783. AuditLogChangeKeyID AuditLogChangeKey = "id"
  784. AuditLogChangeKeyType AuditLogChangeKey = "type"
  785. AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons"
  786. AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior"
  787. AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
  788. )
  789. // AuditLogOptions optional data for the AuditLog
  790. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  791. type AuditLogOptions struct {
  792. DeleteMemberDays string `json:"delete_member_days"`
  793. MembersRemoved string `json:"members_removed"`
  794. ChannelID string `json:"channel_id"`
  795. MessageID string `json:"message_id"`
  796. Count string `json:"count"`
  797. ID string `json:"id"`
  798. Type *AuditLogOptionsType `json:"type"`
  799. RoleName string `json:"role_name"`
  800. }
  801. // AuditLogOptionsType of the AuditLogOption
  802. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  803. type AuditLogOptionsType string
  804. // Valid Types for AuditLogOptionsType
  805. const (
  806. AuditLogOptionsTypeMember AuditLogOptionsType = "member"
  807. AuditLogOptionsTypeRole AuditLogOptionsType = "role"
  808. )
  809. // AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
  810. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
  811. type AuditLogAction int
  812. // Block contains Discord Audit Log Action Types
  813. const (
  814. AuditLogActionGuildUpdate AuditLogAction = 1
  815. AuditLogActionChannelCreate AuditLogAction = 10
  816. AuditLogActionChannelUpdate AuditLogAction = 11
  817. AuditLogActionChannelDelete AuditLogAction = 12
  818. AuditLogActionChannelOverwriteCreate AuditLogAction = 13
  819. AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
  820. AuditLogActionChannelOverwriteDelete AuditLogAction = 15
  821. AuditLogActionMemberKick AuditLogAction = 20
  822. AuditLogActionMemberPrune AuditLogAction = 21
  823. AuditLogActionMemberBanAdd AuditLogAction = 22
  824. AuditLogActionMemberBanRemove AuditLogAction = 23
  825. AuditLogActionMemberUpdate AuditLogAction = 24
  826. AuditLogActionMemberRoleUpdate AuditLogAction = 25
  827. AuditLogActionRoleCreate AuditLogAction = 30
  828. AuditLogActionRoleUpdate AuditLogAction = 31
  829. AuditLogActionRoleDelete AuditLogAction = 32
  830. AuditLogActionInviteCreate AuditLogAction = 40
  831. AuditLogActionInviteUpdate AuditLogAction = 41
  832. AuditLogActionInviteDelete AuditLogAction = 42
  833. AuditLogActionWebhookCreate AuditLogAction = 50
  834. AuditLogActionWebhookUpdate AuditLogAction = 51
  835. AuditLogActionWebhookDelete AuditLogAction = 52
  836. AuditLogActionEmojiCreate AuditLogAction = 60
  837. AuditLogActionEmojiUpdate AuditLogAction = 61
  838. AuditLogActionEmojiDelete AuditLogAction = 62
  839. AuditLogActionMessageDelete AuditLogAction = 72
  840. AuditLogActionMessageBulkDelete AuditLogAction = 73
  841. AuditLogActionMessagePin AuditLogAction = 74
  842. AuditLogActionMessageUnpin AuditLogAction = 75
  843. AuditLogActionIntegrationCreate AuditLogAction = 80
  844. AuditLogActionIntegrationUpdate AuditLogAction = 81
  845. AuditLogActionIntegrationDelete AuditLogAction = 82
  846. )
  847. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  848. type UserGuildSettingsChannelOverride struct {
  849. Muted bool `json:"muted"`
  850. MessageNotifications int `json:"message_notifications"`
  851. ChannelID string `json:"channel_id"`
  852. }
  853. // A UserGuildSettings stores data for a users guild settings.
  854. type UserGuildSettings struct {
  855. SupressEveryone bool `json:"suppress_everyone"`
  856. Muted bool `json:"muted"`
  857. MobilePush bool `json:"mobile_push"`
  858. MessageNotifications int `json:"message_notifications"`
  859. GuildID string `json:"guild_id"`
  860. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  861. }
  862. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  863. type UserGuildSettingsEdit struct {
  864. SupressEveryone bool `json:"suppress_everyone"`
  865. Muted bool `json:"muted"`
  866. MobilePush bool `json:"mobile_push"`
  867. MessageNotifications int `json:"message_notifications"`
  868. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  869. }
  870. // An APIErrorMessage is an api error message returned from discord
  871. type APIErrorMessage struct {
  872. Code int `json:"code"`
  873. Message string `json:"message"`
  874. }
  875. // MessageReaction stores the data for a message reaction.
  876. type MessageReaction struct {
  877. UserID string `json:"user_id"`
  878. MessageID string `json:"message_id"`
  879. Emoji Emoji `json:"emoji"`
  880. ChannelID string `json:"channel_id"`
  881. GuildID string `json:"guild_id,omitempty"`
  882. }
  883. // GatewayBotResponse stores the data for the gateway/bot response
  884. type GatewayBotResponse struct {
  885. URL string `json:"url"`
  886. Shards int `json:"shards"`
  887. }
  888. // GatewayStatusUpdate is sent by the client to indicate a presence or status update
  889. // https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  890. type GatewayStatusUpdate struct {
  891. Since int `json:"since"`
  892. Game Activity `json:"game"`
  893. Status string `json:"status"`
  894. AFK bool `json:"afk"`
  895. }
  896. // Activity defines the Activity sent with GatewayStatusUpdate
  897. // https://discord.com/developers/docs/topics/gateway#activity-object
  898. type Activity struct {
  899. Name string `json:"name"`
  900. Type ActivityType `json:"type"`
  901. URL string `json:"url,omitempty"`
  902. }
  903. // ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
  904. // https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
  905. type ActivityType int
  906. // Valid ActivityType values
  907. const (
  908. ActivityTypeGame ActivityType = iota
  909. ActivityTypeStreaming
  910. ActivityTypeListening
  911. // ActivityTypeWatching // not valid in this use case?
  912. ActivityTypeCustom = 4
  913. )
  914. // Identify is sent during initial handshake with the discord gateway.
  915. // https://discord.com/developers/docs/topics/gateway#identify
  916. type Identify struct {
  917. Token string `json:"token"`
  918. Properties IdentifyProperties `json:"properties"`
  919. Compress bool `json:"compress"`
  920. LargeThreshold int `json:"large_threshold"`
  921. Shard *[2]int `json:"shard,omitempty"`
  922. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  923. GuildSubscriptions bool `json:"guild_subscriptions"`
  924. Intents Intent `json:"intents"`
  925. }
  926. // IdentifyProperties contains the "properties" portion of an Identify packet
  927. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  928. type IdentifyProperties struct {
  929. OS string `json:"$os"`
  930. Browser string `json:"$browser"`
  931. Device string `json:"$device"`
  932. Referer string `json:"$referer"`
  933. ReferringDomain string `json:"$referring_domain"`
  934. }
  935. // Constants for the different bit offsets of text channel permissions
  936. const (
  937. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  938. PermissionReadMessages = 1 << (iota + 10)
  939. PermissionSendMessages
  940. PermissionSendTTSMessages
  941. PermissionManageMessages
  942. PermissionEmbedLinks
  943. PermissionAttachFiles
  944. PermissionReadMessageHistory
  945. PermissionMentionEveryone
  946. PermissionUseExternalEmojis
  947. )
  948. // Constants for the different bit offsets of voice permissions
  949. const (
  950. PermissionVoiceConnect = 1 << (iota + 20)
  951. PermissionVoiceSpeak
  952. PermissionVoiceMuteMembers
  953. PermissionVoiceDeafenMembers
  954. PermissionVoiceMoveMembers
  955. PermissionVoiceUseVAD
  956. PermissionVoicePrioritySpeaker = 1 << (iota + 2)
  957. )
  958. // Constants for general management.
  959. const (
  960. PermissionChangeNickname = 1 << (iota + 26)
  961. PermissionManageNicknames
  962. PermissionManageRoles
  963. PermissionManageWebhooks
  964. PermissionManageEmojis
  965. )
  966. // Constants for the different bit offsets of general permissions
  967. const (
  968. PermissionCreateInstantInvite = 1 << iota
  969. PermissionKickMembers
  970. PermissionBanMembers
  971. PermissionAdministrator
  972. PermissionManageChannels
  973. PermissionManageServer
  974. PermissionAddReactions
  975. PermissionViewAuditLogs
  976. PermissionViewChannel = 1 << (iota + 2)
  977. PermissionAllText = PermissionViewChannel |
  978. PermissionSendMessages |
  979. PermissionSendTTSMessages |
  980. PermissionManageMessages |
  981. PermissionEmbedLinks |
  982. PermissionAttachFiles |
  983. PermissionReadMessageHistory |
  984. PermissionMentionEveryone
  985. PermissionAllVoice = PermissionViewChannel |
  986. PermissionVoiceConnect |
  987. PermissionVoiceSpeak |
  988. PermissionVoiceMuteMembers |
  989. PermissionVoiceDeafenMembers |
  990. PermissionVoiceMoveMembers |
  991. PermissionVoiceUseVAD |
  992. PermissionVoicePrioritySpeaker
  993. PermissionAllChannel = PermissionAllText |
  994. PermissionAllVoice |
  995. PermissionCreateInstantInvite |
  996. PermissionManageRoles |
  997. PermissionManageChannels |
  998. PermissionAddReactions |
  999. PermissionViewAuditLogs
  1000. PermissionAll = PermissionAllChannel |
  1001. PermissionKickMembers |
  1002. PermissionBanMembers |
  1003. PermissionManageServer |
  1004. PermissionAdministrator |
  1005. PermissionManageWebhooks |
  1006. PermissionManageEmojis
  1007. )
  1008. // Block contains Discord JSON Error Response codes
  1009. const (
  1010. ErrCodeUnknownAccount = 10001
  1011. ErrCodeUnknownApplication = 10002
  1012. ErrCodeUnknownChannel = 10003
  1013. ErrCodeUnknownGuild = 10004
  1014. ErrCodeUnknownIntegration = 10005
  1015. ErrCodeUnknownInvite = 10006
  1016. ErrCodeUnknownMember = 10007
  1017. ErrCodeUnknownMessage = 10008
  1018. ErrCodeUnknownOverwrite = 10009
  1019. ErrCodeUnknownProvider = 10010
  1020. ErrCodeUnknownRole = 10011
  1021. ErrCodeUnknownToken = 10012
  1022. ErrCodeUnknownUser = 10013
  1023. ErrCodeUnknownEmoji = 10014
  1024. ErrCodeUnknownWebhook = 10015
  1025. ErrCodeUnknownBan = 10026
  1026. ErrCodeBotsCannotUseEndpoint = 20001
  1027. ErrCodeOnlyBotsCanUseEndpoint = 20002
  1028. ErrCodeMaximumGuildsReached = 30001
  1029. ErrCodeMaximumFriendsReached = 30002
  1030. ErrCodeMaximumPinsReached = 30003
  1031. ErrCodeMaximumGuildRolesReached = 30005
  1032. ErrCodeTooManyReactions = 30010
  1033. ErrCodeUnauthorized = 40001
  1034. ErrCodeMissingAccess = 50001
  1035. ErrCodeInvalidAccountType = 50002
  1036. ErrCodeCannotExecuteActionOnDMChannel = 50003
  1037. ErrCodeEmbedDisabled = 50004
  1038. ErrCodeCannotEditFromAnotherUser = 50005
  1039. ErrCodeCannotSendEmptyMessage = 50006
  1040. ErrCodeCannotSendMessagesToThisUser = 50007
  1041. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  1042. ErrCodeChannelVerificationLevelTooHigh = 50009
  1043. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  1044. ErrCodeOAuth2ApplicationLimitReached = 50011
  1045. ErrCodeInvalidOAuthState = 50012
  1046. ErrCodeMissingPermissions = 50013
  1047. ErrCodeInvalidAuthenticationToken = 50014
  1048. ErrCodeNoteTooLong = 50015
  1049. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  1050. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  1051. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  1052. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  1053. ErrCodeInvalidFormBody = 50035
  1054. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  1055. ErrCodeReactionBlocked = 90001
  1056. )
  1057. // Intent is the type of a Gateway Intent
  1058. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  1059. type Intent int
  1060. // Constants for the different bit offsets of intents
  1061. const (
  1062. IntentsGuilds Intent = 1 << iota
  1063. IntentsGuildMembers
  1064. IntentsGuildBans
  1065. IntentsGuildEmojis
  1066. IntentsGuildIntegrations
  1067. IntentsGuildWebhooks
  1068. IntentsGuildInvites
  1069. IntentsGuildVoiceStates
  1070. IntentsGuildPresences
  1071. IntentsGuildMessages
  1072. IntentsGuildMessageReactions
  1073. IntentsGuildMessageTyping
  1074. IntentsDirectMessages
  1075. IntentsDirectMessageReactions
  1076. IntentsDirectMessageTyping
  1077. IntentsAllWithoutPrivileged = IntentsGuilds |
  1078. IntentsGuildBans |
  1079. IntentsGuildEmojis |
  1080. IntentsGuildIntegrations |
  1081. IntentsGuildWebhooks |
  1082. IntentsGuildInvites |
  1083. IntentsGuildVoiceStates |
  1084. IntentsGuildMessages |
  1085. IntentsGuildMessageReactions |
  1086. IntentsGuildMessageTyping |
  1087. IntentsDirectMessages |
  1088. IntentsDirectMessageReactions |
  1089. IntentsDirectMessageTyping
  1090. IntentsAll = IntentsAllWithoutPrivileged |
  1091. IntentsGuildMembers |
  1092. IntentsGuildPresences
  1093. IntentsNone Intent = 0
  1094. )
  1095. // MakeIntent used to help convert a gateway intent value for use in the Identify structure;
  1096. // this was useful to help support the use of a pointer type when intents were optional.
  1097. // This is now a no-op, and is not necessary to use.
  1098. func MakeIntent(intents Intent) Intent {
  1099. return intents
  1100. }