structs.go 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853
  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. "regexp"
  16. "strings"
  17. "sync"
  18. "time"
  19. "github.com/gorilla/websocket"
  20. )
  21. // A Session represents a connection to the Discord API.
  22. type Session struct {
  23. sync.RWMutex
  24. // General configurable settings.
  25. // Authentication token for this session
  26. // TODO: Remove Below, Deprecated, Use Identify struct
  27. Token string
  28. MFA bool
  29. // Debug for printing JSON request/responses
  30. Debug bool // Deprecated, will be removed.
  31. LogLevel int
  32. // Should the session reconnect the websocket on errors.
  33. ShouldReconnectOnError bool
  34. // Identify is sent during initial handshake with the discord gateway.
  35. // https://discord.com/developers/docs/topics/gateway#identify
  36. Identify Identify
  37. // TODO: Remove Below, Deprecated, Use Identify struct
  38. // Should the session request compressed websocket data.
  39. Compress bool
  40. // Sharding
  41. ShardID int
  42. ShardCount int
  43. // Should state tracking be enabled.
  44. // State tracking is the best way for getting the the users
  45. // active guilds and the members of the guilds.
  46. StateEnabled bool
  47. // Whether or not to call event handlers synchronously.
  48. // e.g false = launch event handlers in their own goroutines.
  49. SyncEvents bool
  50. // Exposed but should not be modified by User.
  51. // Whether the Data Websocket is ready
  52. DataReady bool // NOTE: Maye be deprecated soon
  53. // Max number of REST API retries
  54. MaxRestRetries int
  55. // Status stores the currect status of the websocket connection
  56. // this is being tested, may stay, may go away.
  57. status int32
  58. // Whether the Voice Websocket is ready
  59. VoiceReady bool // NOTE: Deprecated.
  60. // Whether the UDP Connection is ready
  61. UDPReady bool // NOTE: Deprecated
  62. // Stores a mapping of guild id's to VoiceConnections
  63. VoiceConnections map[string]*VoiceConnection
  64. // Managed state object, updated internally with events when
  65. // StateEnabled is true.
  66. State *State
  67. // The http client used for REST requests
  68. Client *http.Client
  69. // The user agent used for REST APIs
  70. UserAgent string
  71. // Stores the last HeartbeatAck that was received (in UTC)
  72. LastHeartbeatAck time.Time
  73. // Stores the last Heartbeat sent (in UTC)
  74. LastHeartbeatSent time.Time
  75. // used to deal with rate limits
  76. Ratelimiter *RateLimiter
  77. // Event handlers
  78. handlersMu sync.RWMutex
  79. handlers map[string][]*eventHandlerInstance
  80. onceHandlers map[string][]*eventHandlerInstance
  81. // The websocket connection.
  82. wsConn *websocket.Conn
  83. // When nil, the session is not listening.
  84. listening chan interface{}
  85. // sequence tracks the current gateway api websocket sequence number
  86. sequence *int64
  87. // stores sessions current Discord Gateway
  88. gateway string
  89. // stores session ID of current Gateway connection
  90. sessionID string
  91. // used to make sure gateway websocket writes do not happen concurrently
  92. wsMutex sync.Mutex
  93. }
  94. // UserConnection is a Connection returned from the UserConnections endpoint
  95. type UserConnection struct {
  96. ID string `json:"id"`
  97. Name string `json:"name"`
  98. Type string `json:"type"`
  99. Revoked bool `json:"revoked"`
  100. Integrations []*Integration `json:"integrations"`
  101. }
  102. // Integration stores integration information
  103. type Integration struct {
  104. ID string `json:"id"`
  105. Name string `json:"name"`
  106. Type string `json:"type"`
  107. Enabled bool `json:"enabled"`
  108. Syncing bool `json:"syncing"`
  109. RoleID string `json:"role_id"`
  110. EnableEmoticons bool `json:"enable_emoticons"`
  111. ExpireBehavior ExpireBehavior `json:"expire_behavior"`
  112. ExpireGracePeriod int `json:"expire_grace_period"`
  113. User *User `json:"user"`
  114. Account IntegrationAccount `json:"account"`
  115. SyncedAt time.Time `json:"synced_at"`
  116. }
  117. // ExpireBehavior of Integration
  118. // https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
  119. type ExpireBehavior int
  120. // Block of valid ExpireBehaviors
  121. const (
  122. ExpireBehaviorRemoveRole ExpireBehavior = 0
  123. ExpireBehaviorKick ExpireBehavior = 1
  124. )
  125. // IntegrationAccount is integration account information
  126. // sent by the UserConnections endpoint
  127. type IntegrationAccount struct {
  128. ID string `json:"id"`
  129. Name string `json:"name"`
  130. }
  131. // A VoiceRegion stores data for a specific voice region server.
  132. type VoiceRegion struct {
  133. ID string `json:"id"`
  134. Name string `json:"name"`
  135. Hostname string `json:"sample_hostname"`
  136. Port int `json:"sample_port"`
  137. }
  138. // A VoiceICE stores data for voice ICE servers.
  139. type VoiceICE struct {
  140. TTL string `json:"ttl"`
  141. Servers []*ICEServer `json:"servers"`
  142. }
  143. // A ICEServer stores data for a specific voice ICE server.
  144. type ICEServer struct {
  145. URL string `json:"url"`
  146. Username string `json:"username"`
  147. Credential string `json:"credential"`
  148. }
  149. // A Invite stores all data related to a specific Discord Guild or Channel invite.
  150. type Invite struct {
  151. Guild *Guild `json:"guild"`
  152. Channel *Channel `json:"channel"`
  153. Inviter *User `json:"inviter"`
  154. Code string `json:"code"`
  155. CreatedAt time.Time `json:"created_at"`
  156. MaxAge int `json:"max_age"`
  157. Uses int `json:"uses"`
  158. MaxUses int `json:"max_uses"`
  159. Revoked bool `json:"revoked"`
  160. Temporary bool `json:"temporary"`
  161. Unique bool `json:"unique"`
  162. TargetUser *User `json:"target_user"`
  163. TargetUserType TargetUserType `json:"target_user_type"`
  164. // will only be filled when using InviteWithCounts
  165. ApproximatePresenceCount int `json:"approximate_presence_count"`
  166. ApproximateMemberCount int `json:"approximate_member_count"`
  167. }
  168. // TargetUserType is the type of the target user
  169. // https://discord.com/developers/docs/resources/invite#invite-object-target-user-types
  170. type TargetUserType int
  171. // Block contains known TargetUserType values
  172. const (
  173. TargetUserTypeStream TargetUserType = 1
  174. )
  175. // ChannelType is the type of a Channel
  176. type ChannelType int
  177. // Block contains known ChannelType values
  178. const (
  179. ChannelTypeGuildText ChannelType = 0
  180. ChannelTypeDM ChannelType = 1
  181. ChannelTypeGuildVoice ChannelType = 2
  182. ChannelTypeGroupDM ChannelType = 3
  183. ChannelTypeGuildCategory ChannelType = 4
  184. ChannelTypeGuildNews ChannelType = 5
  185. ChannelTypeGuildStore ChannelType = 6
  186. ChannelTypeGuildNewsThread ChannelType = 10
  187. ChannelTypeGuildPublicThread ChannelType = 11
  188. ChannelTypeGuildPrivateThread ChannelType = 12
  189. )
  190. // A Channel holds all data related to an individual Discord channel.
  191. type Channel struct {
  192. // The ID of the channel.
  193. ID string `json:"id"`
  194. // The ID of the guild to which the channel belongs, if it is in a guild.
  195. // Else, this ID is empty (e.g. DM channels).
  196. GuildID string `json:"guild_id"`
  197. // The name of the channel.
  198. Name string `json:"name"`
  199. // The topic of the channel.
  200. Topic string `json:"topic"`
  201. // The type of the channel.
  202. Type ChannelType `json:"type"`
  203. // The ID of the last message sent in the channel. This is not
  204. // guaranteed to be an ID of a valid message.
  205. LastMessageID string `json:"last_message_id"`
  206. // The timestamp of the last pinned message in the channel.
  207. // nil if the channel has no pinned messages.
  208. LastPinTimestamp *time.Time `json:"last_pin_timestamp"`
  209. // An approximate count of messages in a thread, stops counting at 50
  210. MessageCount int `json:"message_count"`
  211. // An approximate count of users in a thread, stops counting at 50
  212. MemberCount int `json:"member_count"`
  213. // Whether the channel is marked as NSFW.
  214. NSFW bool `json:"nsfw"`
  215. // Icon of the group DM channel.
  216. Icon string `json:"icon"`
  217. // The position of the channel, used for sorting in client.
  218. Position int `json:"position"`
  219. // The bitrate of the channel, if it is a voice channel.
  220. Bitrate int `json:"bitrate"`
  221. // The recipients of the channel. This is only populated in DM channels.
  222. Recipients []*User `json:"recipients"`
  223. // The messages in the channel. This is only present in state-cached channels,
  224. // and State.MaxMessageCount must be non-zero.
  225. Messages []*Message `json:"-"`
  226. // A list of permission overwrites present for the channel.
  227. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
  228. // The user limit of the voice channel.
  229. UserLimit int `json:"user_limit"`
  230. // The ID of the parent channel, if the channel is under a category. For threads - id of the channel thread was created in.
  231. ParentID string `json:"parent_id"`
  232. // Amount of seconds a user has to wait before sending another message or creating another thread (0-21600)
  233. // bots, as well as users with the permission manage_messages or manage_channel, are unaffected
  234. RateLimitPerUser int `json:"rate_limit_per_user"`
  235. // ID of the creator of the group DM or thread
  236. OwnerID string `json:"owner_id"`
  237. // ApplicationID of the DM creator Zeroed if guild channel or not a bot user
  238. ApplicationID string `json:"application_id"`
  239. // Thread-specific fields not needed by other channels
  240. ThreadMetadata *ThreadMetadata `json:"thread_metadata,omitempty"`
  241. // Thread member object for the current user, if they have joined the thread, only included on certain API endpoints
  242. Member *ThreadMember `json:"thread_member"`
  243. // All thread members. State channels only.
  244. Members []*ThreadMember `json:"-"`
  245. }
  246. // Mention returns a string which mentions the channel
  247. func (c *Channel) Mention() string {
  248. return fmt.Sprintf("<#%s>", c.ID)
  249. }
  250. // IsThread is a helper function to determine if channel is a thread or not
  251. func (c *Channel) IsThread() bool {
  252. return c.Type == ChannelTypeGuildPublicThread || c.Type == ChannelTypeGuildPrivateThread || c.Type == ChannelTypeGuildNewsThread
  253. }
  254. // A ChannelEdit holds Channel Field data for a channel edit.
  255. type ChannelEdit struct {
  256. Name string `json:"name,omitempty"`
  257. Topic string `json:"topic,omitempty"`
  258. NSFW bool `json:"nsfw,omitempty"`
  259. Position int `json:"position"`
  260. Bitrate int `json:"bitrate,omitempty"`
  261. UserLimit int `json:"user_limit,omitempty"`
  262. PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
  263. ParentID string `json:"parent_id,omitempty"`
  264. RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
  265. // NOTE: threads only
  266. Archived bool `json:"archived,omitempty"`
  267. AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
  268. Locked bool `json:"locked,bool"`
  269. Invitable bool `json:"invitable,omitempty"`
  270. }
  271. // A ChannelFollow holds data returned after following a news channel
  272. type ChannelFollow struct {
  273. ChannelID string `json:"channel_id"`
  274. WebhookID string `json:"webhook_id"`
  275. }
  276. // PermissionOverwriteType represents the type of resource on which
  277. // a permission overwrite acts.
  278. type PermissionOverwriteType int
  279. // The possible permission overwrite types.
  280. const (
  281. PermissionOverwriteTypeRole PermissionOverwriteType = 0
  282. PermissionOverwriteTypeMember PermissionOverwriteType = 1
  283. )
  284. // A PermissionOverwrite holds permission overwrite data for a Channel
  285. type PermissionOverwrite struct {
  286. ID string `json:"id"`
  287. Type PermissionOverwriteType `json:"type"`
  288. Deny int64 `json:"deny,string"`
  289. Allow int64 `json:"allow,string"`
  290. }
  291. // ThreadStart stores all parameters you can use with MessageThreadStartComplex or ThreadStartComplex
  292. type ThreadStart struct {
  293. Name string `json:"name"`
  294. AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
  295. Type ChannelType `json:"type,omitempty"`
  296. Invitable bool `json:"invitable"`
  297. RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
  298. }
  299. // ThreadMetadata contains a number of thread-specific channel fields that are not needed by other channel types.
  300. type ThreadMetadata struct {
  301. // Whether the thread is archived
  302. Archived bool `json:"archived"`
  303. // Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
  304. AutoArchiveDuration int `json:"auto_archive_duration"`
  305. // Timestamp when the thread's archive status was last changed, used for calculating recent activity
  306. ArchiveTimestamp time.Time `json:"archive_timestamp"`
  307. // Whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
  308. Locked bool `json:"locked"`
  309. // Whether non-moderators can add other non-moderators to a thread; only available on private threads
  310. Invitable bool `json:"invitable"`
  311. }
  312. // ThreadMember is used to indicate whether a user has joined a thread or not.
  313. // NOTE: ID and UserID are empty (omitted) on the member sent within each thread in the GUILD_CREATE event.
  314. type ThreadMember struct {
  315. // The id of the thread
  316. ID string `json:"id,omitempty"`
  317. // The id of the user
  318. UserID string `json:"user_id,omitempty"`
  319. // The time the current user last joined the thread
  320. JoinTimestamp time.Time `json:"join_timestamp"`
  321. // Any user-thread settings, currently only used for notifications
  322. Flags int
  323. }
  324. // ThreadsList represents a list of threads alongisde with thread member objects for the current user.
  325. type ThreadsList struct {
  326. Threads []*Channel `json:"threads"`
  327. Members []*ThreadMember `json:"members"`
  328. HasMore bool `json:"has_more"`
  329. }
  330. // AddedThreadMember holds information about the user who was added to the thread
  331. type AddedThreadMember struct {
  332. *ThreadMember
  333. Member *Member `json:"member"`
  334. Presence *Presence `json:"presence"`
  335. }
  336. // Emoji struct holds data related to Emoji's
  337. type Emoji struct {
  338. ID string `json:"id"`
  339. Name string `json:"name"`
  340. Roles []string `json:"roles"`
  341. User *User `json:"user"`
  342. RequireColons bool `json:"require_colons"`
  343. Managed bool `json:"managed"`
  344. Animated bool `json:"animated"`
  345. Available bool `json:"available"`
  346. }
  347. // EmojiRegex is the regex used to find and identify emojis in messages
  348. var (
  349. EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18}>`)
  350. )
  351. // MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
  352. func (e *Emoji) MessageFormat() string {
  353. if e.ID != "" && e.Name != "" {
  354. if e.Animated {
  355. return "<a:" + e.APIName() + ">"
  356. }
  357. return "<:" + e.APIName() + ">"
  358. }
  359. return e.APIName()
  360. }
  361. // APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
  362. func (e *Emoji) APIName() string {
  363. if e.ID != "" && e.Name != "" {
  364. return e.Name + ":" + e.ID
  365. }
  366. if e.Name != "" {
  367. return e.Name
  368. }
  369. return e.ID
  370. }
  371. // StickerFormat is the file format of the Sticker.
  372. type StickerFormat int
  373. // Defines all known Sticker types.
  374. const (
  375. StickerFormatTypePNG StickerFormat = 1
  376. StickerFormatTypeAPNG StickerFormat = 2
  377. StickerFormatTypeLottie StickerFormat = 3
  378. )
  379. // StickerType is the type of sticker.
  380. type StickerType int
  381. // Defines Sticker types.
  382. const (
  383. StickerTypeStandard StickerType = 1
  384. StickerTypeGuild StickerType = 2
  385. )
  386. // Sticker represents a sticker object that can be sent in a Message.
  387. type Sticker struct {
  388. ID string `json:"id"`
  389. PackID string `json:"pack_id"`
  390. Name string `json:"name"`
  391. Description string `json:"description"`
  392. Tags string `json:"tags"`
  393. Type StickerType `json:"type"`
  394. FormatType StickerFormat `json:"format_type"`
  395. Available bool `json:"available"`
  396. GuildID string `json:"guild_id"`
  397. User *User `json:"user"`
  398. SortValue int `json:"sort_value"`
  399. }
  400. // StickerPack represents a pack of standard stickers.
  401. type StickerPack struct {
  402. ID string `json:"id"`
  403. Stickers []*Sticker `json:"stickers"`
  404. Name string `json:"name"`
  405. SKUID string `json:"sku_id"`
  406. CoverStickerID string `json:"cover_sticker_id"`
  407. Description string `json:"description"`
  408. BannerAssetID string `json:"banner_asset_id"`
  409. }
  410. // VerificationLevel type definition
  411. type VerificationLevel int
  412. // Constants for VerificationLevel levels from 0 to 4 inclusive
  413. const (
  414. VerificationLevelNone VerificationLevel = 0
  415. VerificationLevelLow VerificationLevel = 1
  416. VerificationLevelMedium VerificationLevel = 2
  417. VerificationLevelHigh VerificationLevel = 3
  418. VerificationLevelVeryHigh VerificationLevel = 4
  419. )
  420. // ExplicitContentFilterLevel type definition
  421. type ExplicitContentFilterLevel int
  422. // Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
  423. const (
  424. ExplicitContentFilterDisabled ExplicitContentFilterLevel = 0
  425. ExplicitContentFilterMembersWithoutRoles ExplicitContentFilterLevel = 1
  426. ExplicitContentFilterAllMembers ExplicitContentFilterLevel = 2
  427. )
  428. // MfaLevel type definition
  429. type MfaLevel int
  430. // Constants for MfaLevel levels from 0 to 1 inclusive
  431. const (
  432. MfaLevelNone MfaLevel = 0
  433. MfaLevelElevated MfaLevel = 1
  434. )
  435. // PremiumTier type definition
  436. type PremiumTier int
  437. // Constants for PremiumTier levels from 0 to 3 inclusive
  438. const (
  439. PremiumTierNone PremiumTier = 0
  440. PremiumTier1 PremiumTier = 1
  441. PremiumTier2 PremiumTier = 2
  442. PremiumTier3 PremiumTier = 3
  443. )
  444. // A Guild holds all data related to a specific Discord Guild. Guilds are also
  445. // sometimes referred to as Servers in the Discord client.
  446. type Guild struct {
  447. // The ID of the guild.
  448. ID string `json:"id"`
  449. // The name of the guild. (2–100 characters)
  450. Name string `json:"name"`
  451. // The hash of the guild's icon. Use Session.GuildIcon
  452. // to retrieve the icon itself.
  453. Icon string `json:"icon"`
  454. // The voice region of the guild.
  455. Region string `json:"region"`
  456. // The ID of the AFK voice channel.
  457. AfkChannelID string `json:"afk_channel_id"`
  458. // The user ID of the owner of the guild.
  459. OwnerID string `json:"owner_id"`
  460. // If we are the owner of the guild
  461. Owner bool `json:"owner"`
  462. // The time at which the current user joined the guild.
  463. // This field is only present in GUILD_CREATE events and websocket
  464. // update events, and thus is only present in state-cached guilds.
  465. JoinedAt time.Time `json:"joined_at"`
  466. // The hash of the guild's discovery splash.
  467. DiscoverySplash string `json:"discovery_splash"`
  468. // The hash of the guild's splash.
  469. Splash string `json:"splash"`
  470. // The timeout, in seconds, before a user is considered AFK in voice.
  471. AfkTimeout int `json:"afk_timeout"`
  472. // The number of members in the guild.
  473. // This field is only present in GUILD_CREATE events and websocket
  474. // update events, and thus is only present in state-cached guilds.
  475. MemberCount int `json:"member_count"`
  476. // The verification level required for the guild.
  477. VerificationLevel VerificationLevel `json:"verification_level"`
  478. // Whether the guild is considered large. This is
  479. // determined by a member threshold in the identify packet,
  480. // and is currently hard-coded at 250 members in the library.
  481. Large bool `json:"large"`
  482. // The default message notification setting for the guild.
  483. DefaultMessageNotifications MessageNotifications `json:"default_message_notifications"`
  484. // A list of roles in the guild.
  485. Roles []*Role `json:"roles"`
  486. // A list of the custom emojis present in the guild.
  487. Emojis []*Emoji `json:"emojis"`
  488. // A list of the custom stickers present in the guild.
  489. Stickers []*Sticker `json:"stickers"`
  490. // A list of the members in the guild.
  491. // This field is only present in GUILD_CREATE events and websocket
  492. // update events, and thus is only present in state-cached guilds.
  493. Members []*Member `json:"members"`
  494. // A list of partial presence objects for members in the guild.
  495. // This field is only present in GUILD_CREATE events and websocket
  496. // update events, and thus is only present in state-cached guilds.
  497. Presences []*Presence `json:"presences"`
  498. // The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned)
  499. MaxPresences int `json:"max_presences"`
  500. // The maximum number of members for the guild
  501. MaxMembers int `json:"max_members"`
  502. // A list of channels in the guild.
  503. // This field is only present in GUILD_CREATE events and websocket
  504. // update events, and thus is only present in state-cached guilds.
  505. Channels []*Channel `json:"channels"`
  506. // A list of all active threads in the guild that current user has permission to view
  507. // This field is only present in GUILD_CREATE events and websocket
  508. // update events and thus is only present in state-cached guilds.
  509. Threads []*Channel `json:"threads"`
  510. // A list of voice states for the guild.
  511. // This field is only present in GUILD_CREATE events and websocket
  512. // update events, and thus is only present in state-cached guilds.
  513. VoiceStates []*VoiceState `json:"voice_states"`
  514. // Whether this guild is currently unavailable (most likely due to outage).
  515. // This field is only present in GUILD_CREATE events and websocket
  516. // update events, and thus is only present in state-cached guilds.
  517. Unavailable bool `json:"unavailable"`
  518. // The explicit content filter level
  519. ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
  520. // The list of enabled guild features
  521. Features []string `json:"features"`
  522. // Required MFA level for the guild
  523. MfaLevel MfaLevel `json:"mfa_level"`
  524. // The application id of the guild if bot created.
  525. ApplicationID string `json:"application_id"`
  526. // Whether or not the Server Widget is enabled
  527. WidgetEnabled bool `json:"widget_enabled"`
  528. // The Channel ID for the Server Widget
  529. WidgetChannelID string `json:"widget_channel_id"`
  530. // The Channel ID to which system messages are sent (eg join and leave messages)
  531. SystemChannelID string `json:"system_channel_id"`
  532. // The System channel flags
  533. SystemChannelFlags SystemChannelFlag `json:"system_channel_flags"`
  534. // The ID of the rules channel ID, used for rules.
  535. RulesChannelID string `json:"rules_channel_id"`
  536. // the vanity url code for the guild
  537. VanityURLCode string `json:"vanity_url_code"`
  538. // the description for the guild
  539. Description string `json:"description"`
  540. // The hash of the guild's banner
  541. Banner string `json:"banner"`
  542. // The premium tier of the guild
  543. PremiumTier PremiumTier `json:"premium_tier"`
  544. // The total number of users currently boosting this server
  545. PremiumSubscriptionCount int `json:"premium_subscription_count"`
  546. // The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US"
  547. PreferredLocale string `json:"preferred_locale"`
  548. // The id of the channel where admins and moderators of guilds with the "PUBLIC" feature receive notices from Discord
  549. PublicUpdatesChannelID string `json:"public_updates_channel_id"`
  550. // The maximum amount of users in a video channel
  551. MaxVideoChannelUsers int `json:"max_video_channel_users"`
  552. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  553. ApproximateMemberCount int `json:"approximate_member_count"`
  554. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  555. ApproximatePresenceCount int `json:"approximate_presence_count"`
  556. // Permissions of our user
  557. Permissions int64 `json:"permissions,string"`
  558. }
  559. // A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild.
  560. type GuildPreview struct {
  561. // The ID of the guild.
  562. ID string `json:"id"`
  563. // The name of the guild. (2–100 characters)
  564. Name string `json:"name"`
  565. // The hash of the guild's icon. Use Session.GuildIcon
  566. // to retrieve the icon itself.
  567. Icon string `json:"icon"`
  568. // The hash of the guild's splash.
  569. Splash string `json:"splash"`
  570. // The hash of the guild's discovery splash.
  571. DiscoverySplash string `json:"discovery_splash"`
  572. // A list of the custom emojis present in the guild.
  573. Emojis []*Emoji `json:"emojis"`
  574. // The list of enabled guild features
  575. Features []string `json:"features"`
  576. // Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  577. ApproximateMemberCount int `json:"approximate_member_count"`
  578. // Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
  579. ApproximatePresenceCount int `json:"approximate_presence_count"`
  580. // the description for the guild
  581. Description string `json:"description"`
  582. }
  583. // A GuildTemplate represents
  584. type GuildTemplate struct {
  585. // The unique code for the guild template
  586. Code string `json:"code"`
  587. // The name of the template
  588. Name string `json:"name"`
  589. // The description for the template
  590. Description string `json:"description"`
  591. // The number of times this template has been used
  592. UsageCount string `json:"usage_count"`
  593. // The ID of the user who created the template
  594. CreatorID string `json:"creator_id"`
  595. // The user who created the template
  596. Creator *User `json:"creator"`
  597. // The timestamp of when the template was created
  598. CreatedAt time.Time `json:"created_at"`
  599. // The timestamp of when the template was last synced
  600. UpdatedAt time.Time `json:"updated_at"`
  601. // The ID of the guild the template was based on
  602. SourceGuildID string `json:"source_guild_id"`
  603. // The guild 'snapshot' this template contains
  604. SerializedSourceGuild *Guild `json:"serialized_source_guild"`
  605. // Whether the template has unsynced changes
  606. IsDirty bool `json:"is_dirty"`
  607. }
  608. // MessageNotifications is the notification level for a guild
  609. // https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
  610. type MessageNotifications int
  611. // Block containing known MessageNotifications values
  612. const (
  613. MessageNotificationsAllMessages MessageNotifications = 0
  614. MessageNotificationsOnlyMentions MessageNotifications = 1
  615. )
  616. // SystemChannelFlag is the type of flags in the system channel (see SystemChannelFlag* consts)
  617. // https://discord.com/developers/docs/resources/guild#guild-object-system-channel-flags
  618. type SystemChannelFlag int
  619. // Block containing known SystemChannelFlag values
  620. const (
  621. SystemChannelFlagsSuppressJoin SystemChannelFlag = 1 << 0
  622. SystemChannelFlagsSuppressPremium SystemChannelFlag = 1 << 1
  623. )
  624. // IconURL returns a URL to the guild's icon.
  625. func (g *Guild) IconURL() string {
  626. if g.Icon == "" {
  627. return ""
  628. }
  629. if strings.HasPrefix(g.Icon, "a_") {
  630. return EndpointGuildIconAnimated(g.ID, g.Icon)
  631. }
  632. return EndpointGuildIcon(g.ID, g.Icon)
  633. }
  634. // BannerURL returns a URL to the guild's banner.
  635. func (g *Guild) BannerURL() string {
  636. if g.Banner == "" {
  637. return ""
  638. }
  639. return EndpointGuildBanner(g.ID, g.Banner)
  640. }
  641. // A UserGuild holds a brief version of a Guild
  642. type UserGuild struct {
  643. ID string `json:"id"`
  644. Name string `json:"name"`
  645. Icon string `json:"icon"`
  646. Owner bool `json:"owner"`
  647. Permissions int64 `json:"permissions,string"`
  648. }
  649. // A GuildParams stores all the data needed to update discord guild settings
  650. type GuildParams struct {
  651. Name string `json:"name,omitempty"`
  652. Region string `json:"region,omitempty"`
  653. VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
  654. DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
  655. AfkChannelID string `json:"afk_channel_id,omitempty"`
  656. AfkTimeout int `json:"afk_timeout,omitempty"`
  657. Icon string `json:"icon,omitempty"`
  658. OwnerID string `json:"owner_id,omitempty"`
  659. Splash string `json:"splash,omitempty"`
  660. Banner string `json:"banner,omitempty"`
  661. }
  662. // A Role stores information about Discord guild member roles.
  663. type Role struct {
  664. // The ID of the role.
  665. ID string `json:"id"`
  666. // The name of the role.
  667. Name string `json:"name"`
  668. // Whether this role is managed by an integration, and
  669. // thus cannot be manually added to, or taken from, members.
  670. Managed bool `json:"managed"`
  671. // Whether this role is mentionable.
  672. Mentionable bool `json:"mentionable"`
  673. // Whether this role is hoisted (shows up separately in member list).
  674. Hoist bool `json:"hoist"`
  675. // The hex color of this role.
  676. Color int `json:"color"`
  677. // The position of this role in the guild's role hierarchy.
  678. Position int `json:"position"`
  679. // The permissions of the role on the guild (doesn't include channel overrides).
  680. // This is a combination of bit masks; the presence of a certain permission can
  681. // be checked by performing a bitwise AND between this int and the permission.
  682. Permissions int64 `json:"permissions,string"`
  683. }
  684. // Mention returns a string which mentions the role
  685. func (r *Role) Mention() string {
  686. return fmt.Sprintf("<@&%s>", r.ID)
  687. }
  688. // Roles are a collection of Role
  689. type Roles []*Role
  690. func (r Roles) Len() int {
  691. return len(r)
  692. }
  693. func (r Roles) Less(i, j int) bool {
  694. return r[i].Position > r[j].Position
  695. }
  696. func (r Roles) Swap(i, j int) {
  697. r[i], r[j] = r[j], r[i]
  698. }
  699. // A VoiceState stores the voice states of Guilds
  700. type VoiceState struct {
  701. UserID string `json:"user_id"`
  702. SessionID string `json:"session_id"`
  703. ChannelID string `json:"channel_id"`
  704. GuildID string `json:"guild_id"`
  705. Suppress bool `json:"suppress"`
  706. SelfMute bool `json:"self_mute"`
  707. SelfDeaf bool `json:"self_deaf"`
  708. Mute bool `json:"mute"`
  709. Deaf bool `json:"deaf"`
  710. }
  711. // A Presence stores the online, offline, or idle and game status of Guild members.
  712. type Presence struct {
  713. User *User `json:"user"`
  714. Status Status `json:"status"`
  715. Activities []*Activity `json:"activities"`
  716. Since *int `json:"since"`
  717. }
  718. // A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
  719. type TimeStamps struct {
  720. EndTimestamp int64 `json:"end,omitempty"`
  721. StartTimestamp int64 `json:"start,omitempty"`
  722. }
  723. // UnmarshalJSON unmarshals JSON into TimeStamps struct
  724. func (t *TimeStamps) UnmarshalJSON(b []byte) error {
  725. temp := struct {
  726. End float64 `json:"end,omitempty"`
  727. Start float64 `json:"start,omitempty"`
  728. }{}
  729. err := json.Unmarshal(b, &temp)
  730. if err != nil {
  731. return err
  732. }
  733. t.EndTimestamp = int64(temp.End)
  734. t.StartTimestamp = int64(temp.Start)
  735. return nil
  736. }
  737. // An Assets struct contains assets and labels used in the rich presence "playing .." Game
  738. type Assets struct {
  739. LargeImageID string `json:"large_image,omitempty"`
  740. SmallImageID string `json:"small_image,omitempty"`
  741. LargeText string `json:"large_text,omitempty"`
  742. SmallText string `json:"small_text,omitempty"`
  743. }
  744. // A Member stores user information for Guild members. A guild
  745. // member represents a certain user's presence in a guild.
  746. type Member struct {
  747. // The guild ID on which the member exists.
  748. GuildID string `json:"guild_id"`
  749. // The time at which the member joined the guild.
  750. JoinedAt time.Time `json:"joined_at"`
  751. // The nickname of the member, if they have one.
  752. Nick string `json:"nick"`
  753. // Whether the member is deafened at a guild level.
  754. Deaf bool `json:"deaf"`
  755. // Whether the member is muted at a guild level.
  756. Mute bool `json:"mute"`
  757. // The underlying user on which the member is based.
  758. User *User `json:"user"`
  759. // A list of IDs of the roles which are possessed by the member.
  760. Roles []string `json:"roles"`
  761. // When the user used their Nitro boost on the server
  762. PremiumSince *time.Time `json:"premium_since"`
  763. // Is true while the member hasn't accepted the membership screen.
  764. Pending bool `json:"pending"`
  765. // Total permissions of the member in the channel, including overrides, returned when in the interaction object.
  766. Permissions int64 `json:"permissions,string"`
  767. // The time at which the member's timeout will expire.
  768. // Time in the past or nil if the user is not timed out.
  769. CommunicationDisabledUntil *time.Time `json:"communication_disabled_until"`
  770. }
  771. // Mention creates a member mention
  772. func (m *Member) Mention() string {
  773. return "<@!" + m.User.ID + ">"
  774. }
  775. // A Settings stores data for a specific users Discord client settings.
  776. type Settings struct {
  777. RenderEmbeds bool `json:"render_embeds"`
  778. InlineEmbedMedia bool `json:"inline_embed_media"`
  779. InlineAttachmentMedia bool `json:"inline_attachment_media"`
  780. EnableTTSCommand bool `json:"enable_tts_command"`
  781. MessageDisplayCompact bool `json:"message_display_compact"`
  782. ShowCurrentGame bool `json:"show_current_game"`
  783. ConvertEmoticons bool `json:"convert_emoticons"`
  784. Locale string `json:"locale"`
  785. Theme string `json:"theme"`
  786. GuildPositions []string `json:"guild_positions"`
  787. RestrictedGuilds []string `json:"restricted_guilds"`
  788. FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
  789. Status Status `json:"status"`
  790. DetectPlatformAccounts bool `json:"detect_platform_accounts"`
  791. DeveloperMode bool `json:"developer_mode"`
  792. }
  793. // Status type definition
  794. type Status string
  795. // Constants for Status with the different current available status
  796. const (
  797. StatusOnline Status = "online"
  798. StatusIdle Status = "idle"
  799. StatusDoNotDisturb Status = "dnd"
  800. StatusInvisible Status = "invisible"
  801. StatusOffline Status = "offline"
  802. )
  803. // FriendSourceFlags stores ... TODO :)
  804. type FriendSourceFlags struct {
  805. All bool `json:"all"`
  806. MutualGuilds bool `json:"mutual_guilds"`
  807. MutualFriends bool `json:"mutual_friends"`
  808. }
  809. // A Relationship between the logged in user and Relationship.User
  810. type Relationship struct {
  811. User *User `json:"user"`
  812. Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
  813. ID string `json:"id"`
  814. }
  815. // A TooManyRequests struct holds information received from Discord
  816. // when receiving a HTTP 429 response.
  817. type TooManyRequests struct {
  818. Bucket string `json:"bucket"`
  819. Message string `json:"message"`
  820. RetryAfter time.Duration `json:"retry_after"`
  821. }
  822. // UnmarshalJSON helps support translation of a milliseconds-based float
  823. // into a time.Duration on TooManyRequests.
  824. func (t *TooManyRequests) UnmarshalJSON(b []byte) error {
  825. u := struct {
  826. Bucket string `json:"bucket"`
  827. Message string `json:"message"`
  828. RetryAfter float64 `json:"retry_after"`
  829. }{}
  830. err := json.Unmarshal(b, &u)
  831. if err != nil {
  832. return err
  833. }
  834. t.Bucket = u.Bucket
  835. t.Message = u.Message
  836. whole, frac := math.Modf(u.RetryAfter)
  837. t.RetryAfter = time.Duration(whole)*time.Second + time.Duration(frac*1000)*time.Millisecond
  838. return nil
  839. }
  840. // A ReadState stores data on the read state of channels.
  841. type ReadState struct {
  842. MentionCount int `json:"mention_count"`
  843. LastMessageID string `json:"last_message_id"`
  844. ID string `json:"id"`
  845. }
  846. // An Ack is used to ack messages
  847. type Ack struct {
  848. Token string `json:"token"`
  849. }
  850. // A GuildRole stores data for guild roles.
  851. type GuildRole struct {
  852. Role *Role `json:"role"`
  853. GuildID string `json:"guild_id"`
  854. }
  855. // A GuildBan stores data for a guild ban.
  856. type GuildBan struct {
  857. Reason string `json:"reason"`
  858. User *User `json:"user"`
  859. }
  860. // A GuildEmbed stores data for a guild embed.
  861. type GuildEmbed struct {
  862. Enabled bool `json:"enabled"`
  863. ChannelID string `json:"channel_id"`
  864. }
  865. // A GuildAuditLog stores data for a guild audit log.
  866. // https://discord.com/developers/docs/resources/audit-log#audit-log-object-audit-log-structure
  867. type GuildAuditLog struct {
  868. Webhooks []*Webhook `json:"webhooks,omitempty"`
  869. Users []*User `json:"users,omitempty"`
  870. AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
  871. Integrations []*Integration `json:"integrations"`
  872. }
  873. // AuditLogEntry for a GuildAuditLog
  874. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-entry-structure
  875. type AuditLogEntry struct {
  876. TargetID string `json:"target_id"`
  877. Changes []*AuditLogChange `json:"changes"`
  878. UserID string `json:"user_id"`
  879. ID string `json:"id"`
  880. ActionType *AuditLogAction `json:"action_type"`
  881. Options *AuditLogOptions `json:"options"`
  882. Reason string `json:"reason"`
  883. }
  884. // AuditLogChange for an AuditLogEntry
  885. type AuditLogChange struct {
  886. NewValue interface{} `json:"new_value"`
  887. OldValue interface{} `json:"old_value"`
  888. Key *AuditLogChangeKey `json:"key"`
  889. }
  890. // AuditLogChangeKey value for AuditLogChange
  891. // https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
  892. type AuditLogChangeKey string
  893. // Block of valid AuditLogChangeKey
  894. const (
  895. // AuditLogChangeKeyAfkChannelID is sent when afk channel changed (snowflake) - guild
  896. AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
  897. // AuditLogChangeKeyAfkTimeout is sent when afk timeout duration changed (int) - guild
  898. AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"
  899. // AuditLogChangeKeyAllow is sent when a permission on a text or voice channel was allowed for a role (string) - role
  900. AuditLogChangeKeyAllow AuditLogChangeKey = "allow"
  901. // AudirChangeKeyApplicationID is sent when application id of the added or removed webhook or bot (snowflake) - channel
  902. AuditLogChangeKeyApplicationID AuditLogChangeKey = "application_id"
  903. // AuditLogChangeKeyArchived is sent when thread was archived/unarchived (bool) - thread
  904. AuditLogChangeKeyArchived AuditLogChangeKey = "archived"
  905. // AuditLogChangeKeyAsset is sent when asset is changed (string) - sticker
  906. AuditLogChangeKeyAsset AuditLogChangeKey = "asset"
  907. // AuditLogChangeKeyAutoArchiveDuration is sent when auto archive duration changed (int) - thread
  908. AuditLogChangeKeyAutoArchiveDuration AuditLogChangeKey = "auto_archive_duration"
  909. // AuditLogChangeKeyAvailable is sent when availability of sticker changed (bool) - sticker
  910. AuditLogChangeKeyAvailable AuditLogChangeKey = "available"
  911. // AuditLogChangeKeyAvatarHash is sent when user avatar changed (string) - user
  912. AuditLogChangeKeyAvatarHash AuditLogChangeKey = "avatar_hash"
  913. // AuditLogChangeKeyBannerHash is sent when guild banner changed (string) - guild
  914. AuditLogChangeKeyBannerHash AuditLogChangeKey = "banner_hash"
  915. // AuditLogChangeKeyBitrate is sent when voice channel bitrate changed (int) - channel
  916. AuditLogChangeKeyBitrate AuditLogChangeKey = "bitrate"
  917. // AuditLogChangeKeyChannelID is sent when channel for invite code or guild scheduled event changed (snowflake) - invite or guild scheduled event
  918. AuditLogChangeKeyChannelID AuditLogChangeKey = "channel_id"
  919. // AuditLogChangeKeyCode is sent when invite code changed (string) - invite
  920. AuditLogChangeKeyCode AuditLogChangeKey = "code"
  921. // AuditLogChangeKeyColor is sent when role color changed (int) - role
  922. AuditLogChangeKeyColor AuditLogChangeKey = "color"
  923. // AuditLogChangeKeyCommunicationDisabledUntil is sent when member timeout state changed (ISO8601 timestamp) - member
  924. AuditLogChangeKeyCommunicationDisabledUntil AuditLogChangeKey = "communication_disabled_until"
  925. // AuditLogChangeKeyDeaf is sent when user server deafened/undeafened (bool) - member
  926. AuditLogChangeKeyDeaf AuditLogChangeKey = "deaf"
  927. // AuditLogChangeKeyDefaultAutoArchiveDuration is sent when default auto archive duration for newly created threads changed (int) - channel
  928. AuditLogChangeKeyDefaultAutoArchiveDuration AuditLogChangeKey = "default_auto_archive_duration"
  929. // AuditLogChangeKeyDefaultMessageNotification is sent when default message notification level changed (int) - guild
  930. AuditLogChangeKeyDefaultMessageNotification AuditLogChangeKey = "default_message_notifications"
  931. // AuditLogChangeKeyDeny is sent when a permission on a text or voice channel was denied for a role (string) - role
  932. AuditLogChangeKeyDeny AuditLogChangeKey = "deny"
  933. // AuditLogChangeKeyDescription is sent when description changed (string) - guild, sticker, or guild scheduled event
  934. AuditLogChangeKeyDescription AuditLogChangeKey = "description"
  935. // AuditLogChangeKeyDiscoverySplashHash is sent when discovery splash changed (string) - guild
  936. AuditLogChangeKeyDiscoverySplashHash AuditLogChangeKey = "discovery_splash_hash"
  937. // AuditLogChangeKeyEnableEmoticons is sent when integration emoticons enabled/disabled (bool) - integration
  938. AuditLogChangeKeyEnableEmoticons AuditLogChangeKey = "enable_emoticons"
  939. // AuditLogChangeKeyEntityType is sent when entity type of guild scheduled event was changed (int) - guild scheduled event
  940. AuditLogChangeKeyEntityType AuditLogChangeKey = "entity_type"
  941. // AuditLogChangeKeyExpireBehavior is sent when integration expiring subscriber behavior changed (int) - integration
  942. AuditLogChangeKeyExpireBehavior AuditLogChangeKey = "expire_behavior"
  943. // AuditLogChangeKeyExpireGracePeriod is sent when integration expire grace period changed (int) - integration
  944. AuditLogChangeKeyExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
  945. // AuditLogChangeKeyExplicitContentFilter is sent when change in whose messages are scanned and deleted for explicit content in the server is made (int) - guild
  946. AuditLogChangeKeyExplicitContentFilter AuditLogChangeKey = "explicit_content_filter"
  947. // AuditLogChangeKeyFormatType is sent when format type of sticker changed (int - sticker format type) - sticker
  948. AuditLogChangeKeyFormatType AuditLogChangeKey = "format_type"
  949. // AuditLogChangeKeyGuildID is sent when guild sticker is in changed (snowflake) - sticker
  950. AuditLogChangeKeyGuildID AuditLogChangeKey = "guild_id"
  951. // AuditLogChangeKeyHoist is sent when role is now displayed/no longer displayed separate from online users (bool) - role
  952. AuditLogChangeKeyHoist AuditLogChangeKey = "hoist"
  953. // AuditLogChangeKeyIconHash is sent when icon changed (string) - guild or role
  954. AuditLogChangeKeyIconHash AuditLogChangeKey = "icon_hash"
  955. // AuditLogChangeKeyID is sent when the id of the changed entity - sometimes used in conjunction with other keys (snowflake) - any
  956. AuditLogChangeKeyID AuditLogChangeKey = "id"
  957. // AuditLogChangeKeyInvitable is sent when private thread is now invitable/uninvitable (bool) - thread
  958. AuditLogChangeKeyInvitable AuditLogChangeKey = "invitable"
  959. // AuditLogChangeKeyInviterID is sent when person who created invite code changed (snowflake) - invite
  960. AuditLogChangeKeyInviterID AuditLogChangeKey = "inviter_id"
  961. // AuditLogChangeKeyLocation is sent when channel id for guild scheduled event changed (string) - guild scheduled event
  962. AuditLogChangeKeyLocation AuditLogChangeKey = "location"
  963. // AuditLogChangeKeyLocked is sent when thread was locked/unlocked (bool) - thread
  964. AuditLogChangeKeyLocked AuditLogChangeKey = "locked"
  965. // AuditLogChangeKeyMaxAge is sent when invite code expiration time changed (int) - invite
  966. AuditLogChangeKeyMaxAge AuditLogChangeKey = "max_age"
  967. // AuditLogChangeKeyMaxUses is sent when max number of times invite code can be used changed (int) - invite
  968. AuditLogChangeKeyMaxUses AuditLogChangeKey = "max_uses"
  969. // AuditLogChangeKeyMentionable is sent when role is now mentionable/unmentionable (bool) - role
  970. AuditLogChangeKeyMentionable AuditLogChangeKey = "mentionable"
  971. // AuditLogChangeKeyMfaLevel is sent when two-factor auth requirement changed (int - mfa level) - guild
  972. AuditLogChangeKeyMfaLevel AuditLogChangeKey = "mfa_level"
  973. // AuditLogChangeKeyMute is sent when user server muted/unmuted (bool) - member
  974. AuditLogChangeKeyMute AuditLogChangeKey = "mute"
  975. // AuditLogChangeKeyName is sent when name changed (string) - any
  976. AuditLogChangeKeyName AuditLogChangeKey = "name"
  977. // AuditLogChangeKeyNick is sent when user nickname changed (string) - member
  978. AuditLogChangeKeyNick AuditLogChangeKey = "nick"
  979. // AuditLogChangeKeyNSFW is sent when channel nsfw restriction changed (bool) - channel
  980. AuditLogChangeKeyNSFW AuditLogChangeKey = "nsfw"
  981. // AuditLogChangeKeyOwnerID is sent when owner changed (snowflake) - guild
  982. AuditLogChangeKeyOwnerID AuditLogChangeKey = "owner_id"
  983. // AuditLogChangeKeyPermissionOverwrite is sent when permissions on a channel changed (array of channel overwrite objects) - channel
  984. AuditLogChangeKeyPermissionOverwrite AuditLogChangeKey = "permission_overwrites"
  985. // AuditLogChangeKeyPermissions is sent when permissions for a role changed (string) - role
  986. AuditLogChangeKeyPermissions AuditLogChangeKey = "permissions"
  987. // AuditLogChangeKeyPosition is sent when text or voice channel position changed (int) - channel
  988. AuditLogChangeKeyPosition AuditLogChangeKey = "position"
  989. // AuditLogChangeKeyPreferredLocale is sent when preferred locale changed (string) - guild
  990. AuditLogChangeKeyPreferredLocale AuditLogChangeKey = "preferred_locale"
  991. // AuditLogChangeKeyPrivacylevel is sent when privacy level of the stage instance changed (integer - privacy level) - stage instance or guild scheduled event
  992. AuditLogChangeKeyPrivacylevel AuditLogChangeKey = "privacy_level"
  993. // AuditLogChangeKeyPruneDeleteDays is sent when number of days after which inactive and role-unassigned members are kicked changed (int) - guild
  994. AuditLogChangeKeyPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
  995. // AuditLogChangeKeyPulibUpdatesChannelID is sent when id of the public updates channel changed (snowflake) - guild
  996. AuditLogChangeKeyPulibUpdatesChannelID AuditLogChangeKey = "public_updates_channel_id"
  997. // AuditLogChangeKeyRateLimitPerUser is sent when amount of seconds a user has to wait before sending another message changed (int) - channel
  998. AuditLogChangeKeyRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
  999. // AuditLogChangeKeyRegion is sent when region changed (string) - guild
  1000. AuditLogChangeKeyRegion AuditLogChangeKey = "region"
  1001. // AuditLogChangeKeyRulesChannelID is sent when id of the rules channel changed (snowflake) - guild
  1002. AuditLogChangeKeyRulesChannelID AuditLogChangeKey = "rules_channel_id"
  1003. // AuditLogChangeKeySplashHash is sent when invite splash page artwork changed (string) - guild
  1004. AuditLogChangeKeySplashHash AuditLogChangeKey = "splash_hash"
  1005. // AuditLogChangeKeyStatus is sent when status of guild scheduled event was changed (int - guild scheduled event status) - guild scheduled event
  1006. AuditLogChangeKeyStatus AuditLogChangeKey = "status"
  1007. // AuditLogChangeKeySystemChannelID is sent when id of the system channel changed (snowflake) - guild
  1008. AuditLogChangeKeySystemChannelID AuditLogChangeKey = "system_channel_id"
  1009. // AuditLogChangeKeyTags is sent when related emoji of sticker changed (string) - sticker
  1010. AuditLogChangeKeyTags AuditLogChangeKey = "tags"
  1011. // AuditLogChangeKeyTemporary is sent when invite code is now temporary or never expires (bool) - invite
  1012. AuditLogChangeKeyTemporary AuditLogChangeKey = "temporary"
  1013. // TODO: remove when compatibility is not required
  1014. AuditLogChangeKeyTempoary = AuditLogChangeKeyTemporary
  1015. // AuditLogChangeKeyTopic is sent when text channel topic or stage instance topic changed (string) - channel or stage instance
  1016. AuditLogChangeKeyTopic AuditLogChangeKey = "topic"
  1017. // AuditLogChangeKeyType is sent when type of entity created (int or string) - any
  1018. AuditLogChangeKeyType AuditLogChangeKey = "type"
  1019. // AuditLogChangeKeyUnicodeEmoji is sent when role unicode emoji changed (string) - role
  1020. AuditLogChangeKeyUnicodeEmoji AuditLogChangeKey = "unicode_emoji"
  1021. // AuditLogChangeKeyUserLimit is sent when new user limit in a voice channel set (int) - voice channel
  1022. AuditLogChangeKeyUserLimit AuditLogChangeKey = "user_limit"
  1023. // AuditLogChangeKeyUses is sent when number of times invite code used changed (int) - invite
  1024. AuditLogChangeKeyUses AuditLogChangeKey = "uses"
  1025. // AuditLogChangeKeyVanityURLCode is sent when guild invite vanity url changed (string) - guild
  1026. AuditLogChangeKeyVanityURLCode AuditLogChangeKey = "vanity_url_code"
  1027. // AuditLogChangeKeyVerificationLevel is sent when required verification level changed (int - verification level) - guild
  1028. AuditLogChangeKeyVerificationLevel AuditLogChangeKey = "verification_level"
  1029. // AuditLogChangeKeyWidgetChannelID is sent when channel id of the server widget changed (snowflake) - guild
  1030. AuditLogChangeKeyWidgetChannelID AuditLogChangeKey = "widget_channel_id"
  1031. // AuditLogChangeKeyWidgetEnabled is sent when server widget enabled/disabled (bool) - guild
  1032. AuditLogChangeKeyWidgetEnabled AuditLogChangeKey = "widget_enabled"
  1033. // AuditLogChangeKeyRoleAdd is sent when new role added (array of partial role objects) - guild
  1034. AuditLogChangeKeyRoleAdd AuditLogChangeKey = "$add"
  1035. // AuditLogChangeKeyRoleRemove is sent when role removed (array of partial role objects) - guild
  1036. AuditLogChangeKeyRoleRemove AuditLogChangeKey = "$remove"
  1037. )
  1038. // AuditLogOptions optional data for the AuditLog
  1039. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  1040. type AuditLogOptions struct {
  1041. DeleteMemberDays string `json:"delete_member_days"`
  1042. MembersRemoved string `json:"members_removed"`
  1043. ChannelID string `json:"channel_id"`
  1044. MessageID string `json:"message_id"`
  1045. Count string `json:"count"`
  1046. ID string `json:"id"`
  1047. Type *AuditLogOptionsType `json:"type"`
  1048. RoleName string `json:"role_name"`
  1049. }
  1050. // AuditLogOptionsType of the AuditLogOption
  1051. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
  1052. type AuditLogOptionsType string
  1053. // Valid Types for AuditLogOptionsType
  1054. const (
  1055. AuditLogOptionsTypeMember AuditLogOptionsType = "member"
  1056. AuditLogOptionsTypeRole AuditLogOptionsType = "role"
  1057. )
  1058. // AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
  1059. // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
  1060. type AuditLogAction int
  1061. // Block contains Discord Audit Log Action Types
  1062. const (
  1063. AuditLogActionGuildUpdate AuditLogAction = 1
  1064. AuditLogActionChannelCreate AuditLogAction = 10
  1065. AuditLogActionChannelUpdate AuditLogAction = 11
  1066. AuditLogActionChannelDelete AuditLogAction = 12
  1067. AuditLogActionChannelOverwriteCreate AuditLogAction = 13
  1068. AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
  1069. AuditLogActionChannelOverwriteDelete AuditLogAction = 15
  1070. AuditLogActionMemberKick AuditLogAction = 20
  1071. AuditLogActionMemberPrune AuditLogAction = 21
  1072. AuditLogActionMemberBanAdd AuditLogAction = 22
  1073. AuditLogActionMemberBanRemove AuditLogAction = 23
  1074. AuditLogActionMemberUpdate AuditLogAction = 24
  1075. AuditLogActionMemberRoleUpdate AuditLogAction = 25
  1076. AuditLogActionMemberMove AuditLogAction = 26
  1077. AuditLogActionMemberDisconnect AuditLogAction = 27
  1078. AuditLogActionBotAdd AuditLogAction = 28
  1079. AuditLogActionRoleCreate AuditLogAction = 30
  1080. AuditLogActionRoleUpdate AuditLogAction = 31
  1081. AuditLogActionRoleDelete AuditLogAction = 32
  1082. AuditLogActionInviteCreate AuditLogAction = 40
  1083. AuditLogActionInviteUpdate AuditLogAction = 41
  1084. AuditLogActionInviteDelete AuditLogAction = 42
  1085. AuditLogActionWebhookCreate AuditLogAction = 50
  1086. AuditLogActionWebhookUpdate AuditLogAction = 51
  1087. AuditLogActionWebhookDelete AuditLogAction = 52
  1088. AuditLogActionEmojiCreate AuditLogAction = 60
  1089. AuditLogActionEmojiUpdate AuditLogAction = 61
  1090. AuditLogActionEmojiDelete AuditLogAction = 62
  1091. AuditLogActionMessageDelete AuditLogAction = 72
  1092. AuditLogActionMessageBulkDelete AuditLogAction = 73
  1093. AuditLogActionMessagePin AuditLogAction = 74
  1094. AuditLogActionMessageUnpin AuditLogAction = 75
  1095. AuditLogActionIntegrationCreate AuditLogAction = 80
  1096. AuditLogActionIntegrationUpdate AuditLogAction = 81
  1097. AuditLogActionIntegrationDelete AuditLogAction = 82
  1098. AuditLogActionStageInstanceCreate AuditLogAction = 83
  1099. AuditLogActionStageInstanceUpdate AuditLogAction = 84
  1100. AuditLogActionStageInstanceDelete AuditLogAction = 85
  1101. AuditLogActionStickerCreate AuditLogAction = 90
  1102. AuditLogActionStickerUpdate AuditLogAction = 91
  1103. AuditLogActionStickerDelete AuditLogAction = 92
  1104. AuditLogGuildScheduledEventCreate AuditLogAction = 100
  1105. AuditLogGuildScheduledEventUpdare AuditLogAction = 101
  1106. AuditLogGuildScheduledEventDelete AuditLogAction = 102
  1107. AuditLogActionThreadCreate AuditLogAction = 110
  1108. AuditLogActionThreadUpdate AuditLogAction = 111
  1109. AuditLogActionThreadDelete AuditLogAction = 112
  1110. )
  1111. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.
  1112. type UserGuildSettingsChannelOverride struct {
  1113. Muted bool `json:"muted"`
  1114. MessageNotifications int `json:"message_notifications"`
  1115. ChannelID string `json:"channel_id"`
  1116. }
  1117. // A UserGuildSettings stores data for a users guild settings.
  1118. type UserGuildSettings struct {
  1119. SupressEveryone bool `json:"suppress_everyone"`
  1120. Muted bool `json:"muted"`
  1121. MobilePush bool `json:"mobile_push"`
  1122. MessageNotifications int `json:"message_notifications"`
  1123. GuildID string `json:"guild_id"`
  1124. ChannelOverrides []*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  1125. }
  1126. // A UserGuildSettingsEdit stores data for editing UserGuildSettings
  1127. type UserGuildSettingsEdit struct {
  1128. SupressEveryone bool `json:"suppress_everyone"`
  1129. Muted bool `json:"muted"`
  1130. MobilePush bool `json:"mobile_push"`
  1131. MessageNotifications int `json:"message_notifications"`
  1132. ChannelOverrides map[string]*UserGuildSettingsChannelOverride `json:"channel_overrides"`
  1133. }
  1134. // An APIErrorMessage is an api error message returned from discord
  1135. type APIErrorMessage struct {
  1136. Code int `json:"code"`
  1137. Message string `json:"message"`
  1138. }
  1139. // MessageReaction stores the data for a message reaction.
  1140. type MessageReaction struct {
  1141. UserID string `json:"user_id"`
  1142. MessageID string `json:"message_id"`
  1143. Emoji Emoji `json:"emoji"`
  1144. ChannelID string `json:"channel_id"`
  1145. GuildID string `json:"guild_id,omitempty"`
  1146. }
  1147. // GatewayBotResponse stores the data for the gateway/bot response
  1148. type GatewayBotResponse struct {
  1149. URL string `json:"url"`
  1150. Shards int `json:"shards"`
  1151. SessionStartLimit SessionInformation `json:"session_start_limit"`
  1152. }
  1153. // SessionInformation provides the information for max concurrency sharding
  1154. type SessionInformation struct {
  1155. Total int `json:"total,omitempty"`
  1156. Remaining int `json:"remaining,omitempty"`
  1157. ResetAfter int `json:"reset_after,omitempty"`
  1158. MaxConcurrency int `json:"max_concurrency,omitempty"`
  1159. }
  1160. // GatewayStatusUpdate is sent by the client to indicate a presence or status update
  1161. // https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure
  1162. type GatewayStatusUpdate struct {
  1163. Since int `json:"since"`
  1164. Game Activity `json:"game"`
  1165. Status string `json:"status"`
  1166. AFK bool `json:"afk"`
  1167. }
  1168. // Activity defines the Activity sent with GatewayStatusUpdate
  1169. // https://discord.com/developers/docs/topics/gateway#activity-object
  1170. type Activity struct {
  1171. Name string `json:"name"`
  1172. Type ActivityType `json:"type"`
  1173. URL string `json:"url,omitempty"`
  1174. CreatedAt time.Time `json:"created_at"`
  1175. ApplicationID string `json:"application_id,omitempty"`
  1176. State string `json:"state,omitempty"`
  1177. Details string `json:"details,omitempty"`
  1178. Timestamps TimeStamps `json:"timestamps,omitempty"`
  1179. Emoji Emoji `json:"emoji,omitempty"`
  1180. Party Party `json:"party,omitempty"`
  1181. Assets Assets `json:"assets,omitempty"`
  1182. Secrets Secrets `json:"secrets,omitempty"`
  1183. Instance bool `json:"instance,omitempty"`
  1184. Flags int `json:"flags,omitempty"`
  1185. }
  1186. // UnmarshalJSON is a custom unmarshaljson to make CreatedAt a time.Time instead of an int
  1187. func (activity *Activity) UnmarshalJSON(b []byte) error {
  1188. temp := struct {
  1189. Name string `json:"name"`
  1190. Type ActivityType `json:"type"`
  1191. URL string `json:"url,omitempty"`
  1192. CreatedAt int64 `json:"created_at"`
  1193. ApplicationID string `json:"application_id,omitempty"`
  1194. State string `json:"state,omitempty"`
  1195. Details string `json:"details,omitempty"`
  1196. Timestamps TimeStamps `json:"timestamps,omitempty"`
  1197. Emoji Emoji `json:"emoji,omitempty"`
  1198. Party Party `json:"party,omitempty"`
  1199. Assets Assets `json:"assets,omitempty"`
  1200. Secrets Secrets `json:"secrets,omitempty"`
  1201. Instance bool `json:"instance,omitempty"`
  1202. Flags int `json:"flags,omitempty"`
  1203. }{}
  1204. err := json.Unmarshal(b, &temp)
  1205. if err != nil {
  1206. return err
  1207. }
  1208. activity.CreatedAt = time.Unix(0, temp.CreatedAt*1000000)
  1209. activity.ApplicationID = temp.ApplicationID
  1210. activity.Assets = temp.Assets
  1211. activity.Details = temp.Details
  1212. activity.Emoji = temp.Emoji
  1213. activity.Flags = temp.Flags
  1214. activity.Instance = temp.Instance
  1215. activity.Name = temp.Name
  1216. activity.Party = temp.Party
  1217. activity.Secrets = temp.Secrets
  1218. activity.State = temp.State
  1219. activity.Timestamps = temp.Timestamps
  1220. activity.Type = temp.Type
  1221. activity.URL = temp.URL
  1222. return nil
  1223. }
  1224. // Party defines the Party field in the Activity struct
  1225. // https://discord.com/developers/docs/topics/gateway#activity-object
  1226. type Party struct {
  1227. ID string `json:"id,omitempty"`
  1228. Size []int `json:"size,omitempty"`
  1229. }
  1230. // Secrets defines the Secrets field for the Activity struct
  1231. // https://discord.com/developers/docs/topics/gateway#activity-object
  1232. type Secrets struct {
  1233. Join string `json:"join,omitempty"`
  1234. Spectate string `json:"spectate,omitempty"`
  1235. Match string `json:"match,omitempty"`
  1236. }
  1237. // ActivityType is the type of Activity (see ActivityType* consts) in the Activity struct
  1238. // https://discord.com/developers/docs/topics/gateway#activity-object-activity-types
  1239. type ActivityType int
  1240. // Valid ActivityType values
  1241. const (
  1242. ActivityTypeGame ActivityType = 0
  1243. ActivityTypeStreaming ActivityType = 1
  1244. ActivityTypeListening ActivityType = 2
  1245. ActivityTypeWatching ActivityType = 3
  1246. ActivityTypeCustom ActivityType = 4
  1247. ActivityTypeCompeting ActivityType = 5
  1248. )
  1249. // Identify is sent during initial handshake with the discord gateway.
  1250. // https://discord.com/developers/docs/topics/gateway#identify
  1251. type Identify struct {
  1252. Token string `json:"token"`
  1253. Properties IdentifyProperties `json:"properties"`
  1254. Compress bool `json:"compress"`
  1255. LargeThreshold int `json:"large_threshold"`
  1256. Shard *[2]int `json:"shard,omitempty"`
  1257. Presence GatewayStatusUpdate `json:"presence,omitempty"`
  1258. GuildSubscriptions bool `json:"guild_subscriptions"`
  1259. Intents Intent `json:"intents"`
  1260. }
  1261. // IdentifyProperties contains the "properties" portion of an Identify packet
  1262. // https://discord.com/developers/docs/topics/gateway#identify-identify-connection-properties
  1263. type IdentifyProperties struct {
  1264. OS string `json:"$os"`
  1265. Browser string `json:"$browser"`
  1266. Device string `json:"$device"`
  1267. Referer string `json:"$referer"`
  1268. ReferringDomain string `json:"$referring_domain"`
  1269. }
  1270. // Constants for the different bit offsets of text channel permissions
  1271. const (
  1272. // Deprecated: PermissionReadMessages has been replaced with PermissionViewChannel for text and voice channels
  1273. PermissionReadMessages = 0x0000000000000400
  1274. PermissionSendMessages = 0x0000000000000800
  1275. PermissionSendTTSMessages = 0x0000000000001000
  1276. PermissionManageMessages = 0x0000000000002000
  1277. PermissionEmbedLinks = 0x0000000000004000
  1278. PermissionAttachFiles = 0x0000000000008000
  1279. PermissionReadMessageHistory = 0x0000000000010000
  1280. PermissionMentionEveryone = 0x0000000000020000
  1281. PermissionUseExternalEmojis = 0x0000000000040000
  1282. PermissionUseSlashCommands = 0x0000000080000000
  1283. PermissionManageThreads = 0x0000000400000000
  1284. PermissionCreatePublicThreads = 0x0000000800000000
  1285. PermissionCreatePrivateThreads = 0x0000001000000000
  1286. PermissionSendMessagesInThreads = 0x0000004000000000
  1287. )
  1288. // Constants for the different bit offsets of voice permissions
  1289. const (
  1290. PermissionVoicePrioritySpeaker = 0x0000000000000100
  1291. PermissionVoiceStreamVideo = 0x0000000000000200
  1292. PermissionVoiceConnect = 0x0000000000100000
  1293. PermissionVoiceSpeak = 0x0000000000200000
  1294. PermissionVoiceMuteMembers = 0x0000000000400000
  1295. PermissionVoiceDeafenMembers = 0x0000000000800000
  1296. PermissionVoiceMoveMembers = 0x0000000001000000
  1297. PermissionVoiceUseVAD = 0x0000000002000000
  1298. PermissionVoiceRequestToSpeak = 0x0000000100000000
  1299. )
  1300. // Constants for general management.
  1301. const (
  1302. PermissionChangeNickname = 0x0000000004000000
  1303. PermissionManageNicknames = 0x0000000008000000
  1304. PermissionManageRoles = 0x0000000010000000
  1305. PermissionManageWebhooks = 0x0000000020000000
  1306. PermissionManageEmojis = 0x0000000040000000
  1307. )
  1308. // Constants for the different bit offsets of general permissions
  1309. const (
  1310. PermissionCreateInstantInvite = 0x0000000000000001
  1311. PermissionKickMembers = 0x0000000000000002
  1312. PermissionBanMembers = 0x0000000000000004
  1313. PermissionAdministrator = 0x0000000000000008
  1314. PermissionManageChannels = 0x0000000000000010
  1315. PermissionManageServer = 0x0000000000000020
  1316. PermissionAddReactions = 0x0000000000000040
  1317. PermissionViewAuditLogs = 0x0000000000000080
  1318. PermissionViewChannel = 0x0000000000000400
  1319. PermissionViewGuildInsights = 0x0000000000080000
  1320. PermissionModerateMembers = 0x0000010000000000
  1321. PermissionAllText = PermissionViewChannel |
  1322. PermissionSendMessages |
  1323. PermissionSendTTSMessages |
  1324. PermissionManageMessages |
  1325. PermissionEmbedLinks |
  1326. PermissionAttachFiles |
  1327. PermissionReadMessageHistory |
  1328. PermissionMentionEveryone
  1329. PermissionAllVoice = PermissionViewChannel |
  1330. PermissionVoiceConnect |
  1331. PermissionVoiceSpeak |
  1332. PermissionVoiceMuteMembers |
  1333. PermissionVoiceDeafenMembers |
  1334. PermissionVoiceMoveMembers |
  1335. PermissionVoiceUseVAD |
  1336. PermissionVoicePrioritySpeaker
  1337. PermissionAllChannel = PermissionAllText |
  1338. PermissionAllVoice |
  1339. PermissionCreateInstantInvite |
  1340. PermissionManageRoles |
  1341. PermissionManageChannels |
  1342. PermissionAddReactions |
  1343. PermissionViewAuditLogs
  1344. PermissionAll = PermissionAllChannel |
  1345. PermissionKickMembers |
  1346. PermissionBanMembers |
  1347. PermissionManageServer |
  1348. PermissionAdministrator |
  1349. PermissionManageWebhooks |
  1350. PermissionManageEmojis
  1351. )
  1352. // Block contains Discord JSON Error Response codes
  1353. const (
  1354. ErrCodeGeneralError = 0
  1355. ErrCodeUnknownAccount = 10001
  1356. ErrCodeUnknownApplication = 10002
  1357. ErrCodeUnknownChannel = 10003
  1358. ErrCodeUnknownGuild = 10004
  1359. ErrCodeUnknownIntegration = 10005
  1360. ErrCodeUnknownInvite = 10006
  1361. ErrCodeUnknownMember = 10007
  1362. ErrCodeUnknownMessage = 10008
  1363. ErrCodeUnknownOverwrite = 10009
  1364. ErrCodeUnknownProvider = 10010
  1365. ErrCodeUnknownRole = 10011
  1366. ErrCodeUnknownToken = 10012
  1367. ErrCodeUnknownUser = 10013
  1368. ErrCodeUnknownEmoji = 10014
  1369. ErrCodeUnknownWebhook = 10015
  1370. ErrCodeUnknownWebhookService = 10016
  1371. ErrCodeUnknownSession = 10020
  1372. ErrCodeUnknownBan = 10026
  1373. ErrCodeUnknownSKU = 10027
  1374. ErrCodeUnknownStoreListing = 10028
  1375. ErrCodeUnknownEntitlement = 10029
  1376. ErrCodeUnknownBuild = 10030
  1377. ErrCodeUnknownLobby = 10031
  1378. ErrCodeUnknownBranch = 10032
  1379. ErrCodeUnknownStoreDirectoryLayout = 10033
  1380. ErrCodeUnknownRedistributable = 10036
  1381. ErrCodeUnknownGiftCode = 10038
  1382. ErrCodeUnknownStream = 10049
  1383. ErrCodeUnknownPremiumServerSubscribeCooldown = 10050
  1384. ErrCodeUnknownGuildTemplate = 10057
  1385. ErrCodeUnknownDiscoveryCategory = 10059
  1386. ErrCodeUnknownSticker = 10060
  1387. ErrCodeUnknownInteraction = 10062
  1388. ErrCodeUnknownApplicationCommand = 10063
  1389. ErrCodeUnknownApplicationCommandPermissions = 10066
  1390. ErrCodeUnknownStageInstance = 10067
  1391. ErrCodeUnknownGuildMemberVerificationForm = 10068
  1392. ErrCodeUnknownGuildWelcomeScreen = 10069
  1393. ErrCodeUnknownGuildScheduledEvent = 10070
  1394. ErrCodeUnknownGuildScheduledEventUser = 10071
  1395. ErrCodeBotsCannotUseEndpoint = 20001
  1396. ErrCodeOnlyBotsCanUseEndpoint = 20002
  1397. ErrCodeExplicitContentCannotBeSentToTheDesiredRecipients = 20009
  1398. ErrCodeYouAreNotAuthorizedToPerformThisActionOnThisApplication = 20012
  1399. ErrCodeThisActionCannotBePerformedDueToSlowmodeRateLimit = 20016
  1400. ErrCodeOnlyTheOwnerOfThisAccountCanPerformThisAction = 20018
  1401. ErrCodeMessageCannotBeEditedDueToAnnouncementRateLimits = 20022
  1402. ErrCodeChannelHasHitWriteRateLimit = 20028
  1403. ErrCodeTheWriteActionYouArePerformingOnTheServerHasHitTheWriteRateLimit = 20029
  1404. ErrCodeStageTopicContainsNotAllowedWordsForPublicStages = 20031
  1405. ErrCodeGuildPremiumSubscriptionLevelTooLow = 20035
  1406. ErrCodeMaximumPinsReached = 30003
  1407. ErrCodeMaximumNumberOfRecipientsReached = 30004
  1408. ErrCodeMaximumGuildRolesReached = 30005
  1409. ErrCodeMaximumNumberOfWebhooksReached = 30007
  1410. ErrCodeMaximumNumberOfEmojisReached = 30008
  1411. ErrCodeTooManyReactions = 30010
  1412. ErrCodeMaximumNumberOfGuildChannelsReached = 30013
  1413. ErrCodeMaximumNumberOfAttachmentsInAMessageReached = 30015
  1414. ErrCodeMaximumNumberOfInvitesReached = 30016
  1415. ErrCodeMaximumNumberOfAnimatedEmojisReached = 30018
  1416. ErrCodeMaximumNumberOfServerMembersReached = 30019
  1417. ErrCodeMaximumNumberOfGuildDiscoverySubcategoriesReached = 30030
  1418. ErrCodeGuildAlreadyHasATemplate = 30031
  1419. ErrCodeMaximumNumberOfThreadParticipantsReached = 30033
  1420. ErrCodeMaximumNumberOfBansForNonGuildMembersHaveBeenExceeded = 30035
  1421. ErrCodeMaximumNumberOfBansFetchesHasBeenReached = 30037
  1422. ErrCodeMaximumNumberOfUncompletedGuildScheduledEventsReached = 30038
  1423. ErrCodeMaximumNumberOfStickersReached = 30039
  1424. ErrCodeMaximumNumberOfPruneRequestsHasBeenReached = 30040
  1425. ErrCodeMaximumNumberOfGuildWidgetSettingsUpdatesHasBeenReached = 30042
  1426. ErrCodeMaximumNumberOfEditsToMessagesOlderThanOneHourReached = 30046
  1427. ErrCodeUnauthorized = 40001
  1428. ErrCodeActionRequiredVerifiedAccount = 40002
  1429. ErrCodeOpeningDirectMessagesTooFast = 40003
  1430. ErrCodeSendMessagesHasBeenTemporarilyDisabled = 40004
  1431. ErrCodeRequestEntityTooLarge = 40005
  1432. ErrCodeFeatureTemporarilyDisabledServerSide = 40006
  1433. ErrCodeUserIsBannedFromThisGuild = 40007
  1434. ErrCodeTargetIsNotConnectedToVoice = 40032
  1435. ErrCodeMessageAlreadyCrossposted = 40033
  1436. ErrCodeAnApplicationWithThatNameAlreadyExists = 40041
  1437. ErrCodeInteractionHasAlreadyBeenAcknowledged = 40060
  1438. ErrCodeMissingAccess = 50001
  1439. ErrCodeInvalidAccountType = 50002
  1440. ErrCodeCannotExecuteActionOnDMChannel = 50003
  1441. ErrCodeEmbedDisabled = 50004
  1442. ErrCodeGuildWidgetDisabled = 50004
  1443. ErrCodeCannotEditFromAnotherUser = 50005
  1444. ErrCodeCannotSendEmptyMessage = 50006
  1445. ErrCodeCannotSendMessagesToThisUser = 50007
  1446. ErrCodeCannotSendMessagesInVoiceChannel = 50008
  1447. ErrCodeChannelVerificationLevelTooHigh = 50009
  1448. ErrCodeOAuth2ApplicationDoesNotHaveBot = 50010
  1449. ErrCodeOAuth2ApplicationLimitReached = 50011
  1450. ErrCodeInvalidOAuthState = 50012
  1451. ErrCodeMissingPermissions = 50013
  1452. ErrCodeInvalidAuthenticationToken = 50014
  1453. ErrCodeTooFewOrTooManyMessagesToDelete = 50016
  1454. ErrCodeCanOnlyPinMessageToOriginatingChannel = 50019
  1455. ErrCodeInviteCodeWasEitherInvalidOrTaken = 50020
  1456. ErrCodeCannotExecuteActionOnSystemMessage = 50021
  1457. ErrCodeCannotExecuteActionOnThisChannelType = 50024
  1458. ErrCodeInvalidOAuth2AccessTokenProvided = 50025
  1459. ErrCodeMissingRequiredOAuth2Scope = 50026
  1460. ErrCodeInvalidWebhookTokenProvided = 50027
  1461. ErrCodeInvalidRole = 50028
  1462. ErrCodeInvalidRecipients = 50033
  1463. ErrCodeMessageProvidedTooOldForBulkDelete = 50034
  1464. ErrCodeInvalidFormBody = 50035
  1465. ErrCodeInviteAcceptedToGuildApplicationsBotNotIn = 50036
  1466. ErrCodeInvalidAPIVersionProvided = 50041
  1467. ErrCodeFileUploadedExceedsTheMaximumSize = 50045
  1468. ErrCodeInvalidFileUploaded = 50046
  1469. ErrCodeInvalidGuild = 50055
  1470. ErrCodeInvalidMessageType = 50068
  1471. ErrCodeCannotDeleteAChannelRequiredForCommunityGuilds = 50074
  1472. ErrCodeInvalidStickerSent = 50081
  1473. ErrCodePerformedOperationOnArchivedThread = 50083
  1474. ErrCodeBeforeValueIsEarlierThanThreadCreationDate = 50085
  1475. ErrCodeCommunityServerChannelsMustBeTextChannels = 50086
  1476. ErrCodeThisServerIsNotAvailableInYourLocation = 50095
  1477. ErrCodeThisServerNeedsMonetizationEnabledInOrderToPerformThisAction = 50097
  1478. ErrCodeThisServerNeedsMoreBoostsToPerformThisAction = 50101
  1479. ErrCodeTheRequestBodyContainsInvalidJSON = 50109
  1480. ErrCodeNoUsersWithDiscordTagExist = 80004
  1481. ErrCodeReactionBlocked = 90001
  1482. ErrCodeAPIResourceIsCurrentlyOverloaded = 130000
  1483. ErrCodeTheStageIsAlreadyOpen = 150006
  1484. ErrCodeCannotReplyWithoutPermissionToReadMessageHistory = 160002
  1485. ErrCodeThreadAlreadyCreatedForThisMessage = 160004
  1486. ErrCodeThreadIsLocked = 160005
  1487. ErrCodeMaximumNumberOfActiveThreadsReached = 160006
  1488. ErrCodeMaximumNumberOfActiveAnnouncementThreadsReached = 160007
  1489. ErrCodeInvalidJSONForUploadedLottieFile = 170001
  1490. ErrCodeUploadedLottiesCannotContainRasterizedImages = 170002
  1491. ErrCodeStickerMaximumFramerateExceeded = 170003
  1492. ErrCodeStickerFrameCountExceedsMaximumOfOneThousandFrames = 170004
  1493. ErrCodeLottieAnimationMaximumDimensionsExceeded = 170005
  1494. ErrCodeStickerFrameRateOutOfRange = 170006
  1495. ErrCodeStickerAnimationDurationExceedsMaximumOfFiveSeconds = 170007
  1496. ErrCodeCannotUpdateAFinishedEvent = 180000
  1497. ErrCodeFailedToCreateStageNeededForStageEvent = 180002
  1498. )
  1499. // Intent is the type of a Gateway Intent
  1500. // https://discord.com/developers/docs/topics/gateway#gateway-intents
  1501. type Intent int
  1502. // Constants for the different bit offsets of intents
  1503. const (
  1504. IntentGuilds Intent = 1 << 0
  1505. IntentGuildMembers Intent = 1 << 1
  1506. IntentGuildBans Intent = 1 << 2
  1507. IntentGuildEmojis Intent = 1 << 3
  1508. IntentGuildIntegrations Intent = 1 << 4
  1509. IntentGuildWebhooks Intent = 1 << 5
  1510. IntentGuildInvites Intent = 1 << 6
  1511. IntentGuildVoiceStates Intent = 1 << 7
  1512. IntentGuildPresences Intent = 1 << 8
  1513. IntentGuildMessages Intent = 1 << 9
  1514. IntentGuildMessageReactions Intent = 1 << 10
  1515. IntentGuildMessageTyping Intent = 1 << 11
  1516. IntentDirectMessages Intent = 1 << 12
  1517. IntentDirectMessageReactions Intent = 1 << 13
  1518. IntentDirectMessageTyping Intent = 1 << 14
  1519. IntentMessageContent Intent = 1 << 15
  1520. IntentGuildScheduledEvents Intent = 1 << 16
  1521. // TODO: remove when compatibility is not needed
  1522. IntentsGuilds Intent = 1 << 0
  1523. IntentsGuildMembers Intent = 1 << 1
  1524. IntentsGuildBans Intent = 1 << 2
  1525. IntentsGuildEmojis Intent = 1 << 3
  1526. IntentsGuildIntegrations Intent = 1 << 4
  1527. IntentsGuildWebhooks Intent = 1 << 5
  1528. IntentsGuildInvites Intent = 1 << 6
  1529. IntentsGuildVoiceStates Intent = 1 << 7
  1530. IntentsGuildPresences Intent = 1 << 8
  1531. IntentsGuildMessages Intent = 1 << 9
  1532. IntentsGuildMessageReactions Intent = 1 << 10
  1533. IntentsGuildMessageTyping Intent = 1 << 11
  1534. IntentsDirectMessages Intent = 1 << 12
  1535. IntentsDirectMessageReactions Intent = 1 << 13
  1536. IntentsDirectMessageTyping Intent = 1 << 14
  1537. IntentsMessageContent Intent = 1 << 15
  1538. IntentsGuildScheduledEvents Intent = 1 << 16
  1539. IntentsAllWithoutPrivileged = IntentGuilds |
  1540. IntentGuildBans |
  1541. IntentGuildEmojis |
  1542. IntentGuildIntegrations |
  1543. IntentGuildWebhooks |
  1544. IntentGuildInvites |
  1545. IntentGuildVoiceStates |
  1546. IntentGuildMessages |
  1547. IntentGuildMessageReactions |
  1548. IntentGuildMessageTyping |
  1549. IntentDirectMessages |
  1550. IntentDirectMessageReactions |
  1551. IntentDirectMessageTyping |
  1552. IntentGuildScheduledEvents
  1553. IntentsAll = IntentsAllWithoutPrivileged |
  1554. IntentGuildMembers |
  1555. IntentGuildPresences |
  1556. IntentMessageContent
  1557. IntentsNone Intent = 0
  1558. )
  1559. // MakeIntent used to help convert a gateway intent value for use in the Identify structure;
  1560. // this was useful to help support the use of a pointer type when intents were optional.
  1561. // This is now a no-op, and is not necessary to use.
  1562. func MakeIntent(intents Intent) Intent {
  1563. return intents
  1564. }