aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/bwmarrin/discordgo/restapi.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/bwmarrin/discordgo/restapi.go')
-rw-r--r--vendor/github.com/bwmarrin/discordgo/restapi.go562
1 files changed, 416 insertions, 146 deletions
diff --git a/vendor/github.com/bwmarrin/discordgo/restapi.go b/vendor/github.com/bwmarrin/discordgo/restapi.go
index 41796fe..79af468 100644
--- a/vendor/github.com/bwmarrin/discordgo/restapi.go
+++ b/vendor/github.com/bwmarrin/discordgo/restapi.go
@@ -39,6 +39,59 @@ var (
ErrUnauthorized = errors.New("HTTP request was unauthorized. This could be because the provided token was not a bot token. Please add \"Bot \" to the start of your token. https://discord.com/developers/docs/reference#authentication-example-bot-token-authorization-header")
)
+var (
+ // Marshal defines function used to encode JSON payloads
+ Marshal func(v interface{}) ([]byte, error) = json.Marshal
+ // Unmarshal defines function used to decode JSON payloads
+ Unmarshal func(src []byte, v interface{}) error = json.Unmarshal
+)
+
+// RESTError stores error information about a request with a bad response code.
+// Message is not always present, there are cases where api calls can fail
+// without returning a json message.
+type RESTError struct {
+ Request *http.Request
+ Response *http.Response
+ ResponseBody []byte
+
+ Message *APIErrorMessage // Message may be nil.
+}
+
+// newRestError returns a new REST API error.
+func newRestError(req *http.Request, resp *http.Response, body []byte) *RESTError {
+ restErr := &RESTError{
+ Request: req,
+ Response: resp,
+ ResponseBody: body,
+ }
+
+ // Attempt to decode the error and assume no message was provided if it fails
+ var msg *APIErrorMessage
+ err := Unmarshal(body, &msg)
+ if err == nil {
+ restErr.Message = msg
+ }
+
+ return restErr
+}
+
+// Error returns a Rest API Error with its status code and body.
+func (r RESTError) Error() string {
+ return "HTTP " + r.Response.Status + ", " + string(r.ResponseBody)
+}
+
+// RateLimitError is returned when a request exceeds a rate limit
+// and ShouldRetryOnRateLimit is false. The request may be manually
+// retried after waiting the duration specified by RetryAfter.
+type RateLimitError struct {
+ *RateLimit
+}
+
+// Error returns a rate limit error with rate limited endpoint and retry time.
+func (e RateLimitError) Error() string {
+ return "Rate limit exceeded on " + e.URL + ", retry after " + e.RetryAfter.String()
+}
+
// Request is the same as RequestWithBucketID but the bucket id is the same as the urlStr
func (s *Session) Request(method, urlStr string, data interface{}) (response []byte, err error) {
return s.RequestWithBucketID(method, urlStr, data, strings.SplitN(urlStr, "?", 2)[0])
@@ -48,7 +101,7 @@ func (s *Session) Request(method, urlStr string, data interface{}) (response []b
func (s *Session) RequestWithBucketID(method, urlStr string, data interface{}, bucketID string) (response []byte, err error) {
var body []byte
if data != nil {
- body, err = json.Marshal(data)
+ body, err = Marshal(data)
if err != nil {
return
}
@@ -108,7 +161,7 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
}
defer func() {
err2 := resp.Body.Close()
- if err2 != nil {
+ if s.Debug && err2 != nil {
log.Println("error closing resp body")
}
}()
@@ -147,19 +200,24 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
}
case 429: // TOO MANY REQUESTS - Rate limiting
rl := TooManyRequests{}
- err = json.Unmarshal(response, &rl)
+ err = Unmarshal(response, &rl)
if err != nil {
s.log(LogError, "rate limit unmarshal error, %s", err)
return
}
- s.log(LogInformational, "Rate Limiting %s, retry in %v", urlStr, rl.RetryAfter)
- s.handleEvent(rateLimitEventType, &RateLimit{TooManyRequests: &rl, URL: urlStr})
- time.Sleep(rl.RetryAfter)
- // we can make the above smarter
- // this method can cause longer delays than required
+ if s.ShouldRetryOnRateLimit {
+ s.log(LogInformational, "Rate Limiting %s, retry in %v", urlStr, rl.RetryAfter)
+ s.handleEvent(rateLimitEventType, &RateLimit{TooManyRequests: &rl, URL: urlStr})
+
+ time.Sleep(rl.RetryAfter)
+ // we can make the above smarter
+ // this method can cause longer delays than required
- response, err = s.RequestWithLockedBucket(method, urlStr, contentType, b, s.Ratelimiter.LockBucketObject(bucket), sequence)
+ response, err = s.RequestWithLockedBucket(method, urlStr, contentType, b, s.Ratelimiter.LockBucketObject(bucket), sequence)
+ } else {
+ err = &RateLimitError{&RateLimit{TooManyRequests: &rl, URL: urlStr}}
+ }
case http.StatusUnauthorized:
if strings.Index(s.Token, "Bot ") != 0 {
s.log(LogInformational, ErrUnauthorized.Error())
@@ -174,7 +232,7 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
}
func unmarshal(data []byte, v interface{}) error {
- err := json.Unmarshal(data, v)
+ err := Unmarshal(data, v)
if err != nil {
return fmt.Errorf("%w: %s", ErrJSONUnmarshal, err)
}
@@ -276,6 +334,18 @@ func (s *Session) UserChannelCreate(recipientID string) (st *Channel, err error)
return
}
+// UserGuildMember returns a guild member object for the current user in the given Guild.
+// guildID : ID of the guild
+func (s *Session) UserGuildMember(guildID string) (st *Member, err error) {
+ body, err := s.RequestWithBucketID("GET", EndpointUserGuildMember("@me", guildID), nil, EndpointUserGuildMember("@me", guildID))
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
// UserGuilds returns an array of UserGuild structures for all guilds.
// limit : The number guilds that can be returned. (max 100)
// beforeID : If provided all guilds returned will be before given ID.
@@ -438,6 +508,19 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) {
return
}
+// GuildWithCounts returns a Guild structure of a specific Guild with approximate member and presence counts.
+// guildID : The ID of a Guild
+func (s *Session) GuildWithCounts(guildID string) (st *Guild, err error) {
+
+ body, err := s.RequestWithBucketID("GET", EndpointGuild(guildID)+"?with_counts=true", nil, EndpointGuild(guildID))
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
// GuildPreview returns a GuildPreview structure of a specific public Guild.
// guildID : The ID of a Guild
func (s *Session) GuildPreview(guildID string) (st *GuildPreview, err error) {
@@ -470,7 +553,7 @@ func (s *Session) GuildCreate(name string) (st *Guild, err error) {
// GuildEdit edits a new Guild
// guildID : The ID of a Guild
// g : A GuildParams struct with the values Name, Region and VerificationLevel defined.
-func (s *Session) GuildEdit(guildID string, g GuildParams) (st *Guild, err error) {
+func (s *Session) GuildEdit(guildID string, g *GuildParams) (st *Guild, err error) {
// Bounds checking for VerificationLevel, interval: [0, 4]
if g.VerificationLevel != nil {
@@ -481,7 +564,7 @@ func (s *Session) GuildEdit(guildID string, g GuildParams) (st *Guild, err error
}
}
- //Bounds checking for regions
+ // Bounds checking for regions
if g.Region != "" {
isValid := false
regions, _ := s.VoiceRegions()
@@ -530,12 +613,30 @@ func (s *Session) GuildLeave(guildID string) (err error) {
return
}
-// GuildBans returns an array of GuildBan structures for all bans of a
-// given guild.
-// guildID : The ID of a Guild.
-func (s *Session) GuildBans(guildID string) (st []*GuildBan, err error) {
+// GuildBans returns an array of GuildBan structures for bans in the given guild.
+// guildID : The ID of a Guild
+// limit : Max number of bans to return (max 1000)
+// beforeID : If not empty all returned users will be after the given id
+// afterID : If not empty all returned users will be before the given id
+func (s *Session) GuildBans(guildID string, limit int, beforeID, afterID string) (st []*GuildBan, err error) {
+ uri := EndpointGuildBans(guildID)
- body, err := s.RequestWithBucketID("GET", EndpointGuildBans(guildID), nil, EndpointGuildBans(guildID))
+ v := url.Values{}
+ if limit != 0 {
+ v.Set("limit", strconv.Itoa(limit))
+ }
+ if beforeID != "" {
+ v.Set("before", beforeID)
+ }
+ if afterID != "" {
+ v.Set("after", afterID)
+ }
+
+ if len(v) > 0 {
+ uri += "?" + v.Encode()
+ }
+
+ body, err := s.RequestWithBucketID("GET", uri, nil, EndpointGuildBans(guildID))
if err != nil {
return
}
@@ -631,6 +732,29 @@ func (s *Session) GuildMembers(guildID string, after string, limit int) (st []*M
return
}
+// GuildMembersSearch returns a list of guild member objects whose username or nickname starts with a provided string
+// guildID : The ID of a Guild
+// query : Query string to match username(s) and nickname(s) against
+// limit : Max number of members to return (default 1, min 1, max 1000)
+func (s *Session) GuildMembersSearch(guildID, query string, limit int) (st []*Member, err error) {
+
+ uri := EndpointGuildMembersSearch(guildID)
+
+ queryParams := url.Values{}
+ queryParams.Set("query", query)
+ if limit > 1 {
+ queryParams.Set("limit", strconv.Itoa(limit))
+ }
+
+ body, err := s.RequestWithBucketID("GET", uri+"?"+queryParams.Encode(), nil, uri)
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
// GuildMember returns a member of a guild.
// guildID : The ID of a Guild.
// userID : The ID of a User
@@ -648,22 +772,10 @@ func (s *Session) GuildMember(guildID, userID string) (st *Member, err error) {
}
// GuildMemberAdd force joins a user to the guild.
-// accessToken : Valid access_token for the user.
// guildID : The ID of a Guild.
// userID : The ID of a User.
-// nick : Value to set users nickname to
-// roles : A list of role ID's to set on the member.
-// mute : If the user is muted.
-// deaf : If the user is deafened.
-func (s *Session) GuildMemberAdd(accessToken, guildID, userID, nick string, roles []string, mute, deaf bool) (err error) {
-
- data := struct {
- AccessToken string `json:"access_token"`
- Nick string `json:"nick,omitempty"`
- Roles []string `json:"roles,omitempty"`
- Mute bool `json:"mute,omitempty"`
- Deaf bool `json:"deaf,omitempty"`
- }{accessToken, nick, roles, mute, deaf}
+// data : Parameters of the user to add.
+func (s *Session) GuildMemberAdd(guildID, userID string, data *GuildMemberAddParams) (err error) {
_, err = s.RequestWithBucketID("PUT", EndpointGuildMember(guildID, userID), data, EndpointGuildMember(guildID, ""))
if err != nil {
@@ -696,20 +808,30 @@ func (s *Session) GuildMemberDeleteWithReason(guildID, userID, reason string) (e
return
}
-// GuildMemberEdit edits the roles of a member.
+// GuildMemberEdit edits and returns updated member.
// guildID : The ID of a Guild.
// userID : The ID of a User.
-// roles : A list of role ID's to set on the member.
-func (s *Session) GuildMemberEdit(guildID, userID string, roles []string) (err error) {
-
- data := struct {
- Roles []string `json:"roles"`
- }{roles}
+// data : Updated GuildMember data.
+func (s *Session) GuildMemberEdit(guildID, userID string, data *GuildMemberParams) (st *Member, err error) {
+ var body []byte
+ body, err = s.RequestWithBucketID("PATCH", EndpointGuildMember(guildID, userID), data, EndpointGuildMember(guildID, ""))
+ if err != nil {
+ return nil, err
+ }
- _, err = s.RequestWithBucketID("PATCH", EndpointGuildMember(guildID, userID), data, EndpointGuildMember(guildID, ""))
+ err = unmarshal(body, &st)
return
}
+// GuildMemberEditComplex edits the nickname and roles of a member.
+// NOTE: deprecated, use GuildMemberEdit instead.
+// guildID : The ID of a Guild.
+// userID : The ID of a User.
+// data : A GuildMemberEditData struct with the new nickname and roles
+func (s *Session) GuildMemberEditComplex(guildID, userID string, data *GuildMemberParams) (st *Member, err error) {
+ return s.GuildMemberEdit(guildID, userID, data)
+}
+
// GuildMemberMove moves a guild member from one voice channel to another/none
// guildID : The ID of a Guild.
// userID : The ID of a User.
@@ -904,11 +1026,11 @@ func (s *Session) GuildRoles(guildID string) (st []*Role, err error) {
return // TODO return pointer
}
-// GuildRoleCreate returns a new Guild Role.
-// guildID: The ID of a Guild.
-func (s *Session) GuildRoleCreate(guildID string) (st *Role, err error) {
-
- body, err := s.RequestWithBucketID("POST", EndpointGuildRoles(guildID), nil, EndpointGuildRoles(guildID))
+// GuildRoleCreate creates a new Guild Role and returns it.
+// guildID : The ID of a Guild.
+// data : New Role parameters.
+func (s *Session) GuildRoleCreate(guildID string, data *RoleParams) (st *Role, err error) {
+ body, err := s.RequestWithBucketID("POST", EndpointGuildRoles(guildID), data, EndpointGuildRoles(guildID))
if err != nil {
return
}
@@ -918,30 +1040,17 @@ func (s *Session) GuildRoleCreate(guildID string) (st *Role, err error) {
return
}
-// GuildRoleEdit updates an existing Guild Role with new values
+// GuildRoleEdit updates an existing Guild Role and returns updated Role data.
// guildID : The ID of a Guild.
// roleID : The ID of a Role.
-// name : The name of the Role.
-// color : The color of the role (decimal, not hex).
-// hoist : Whether to display the role's users separately.
-// perm : The permissions for the role.
-// mention : Whether this role is mentionable
-func (s *Session) GuildRoleEdit(guildID, roleID, name string, color int, hoist bool, perm int64, mention bool) (st *Role, err error) {
+// data : Updated Role data.
+func (s *Session) GuildRoleEdit(guildID, roleID string, data *RoleParams) (st *Role, err error) {
// Prevent sending a color int that is too big.
- if color > 0xFFFFFF {
- err = fmt.Errorf("color value cannot be larger than 0xFFFFFF")
- return nil, err
+ if data.Color != nil && *data.Color > 0xFFFFFF {
+ return nil, fmt.Errorf("color value cannot be larger than 0xFFFFFF")
}
- data := struct {
- Name string `json:"name"` // The role's name (overwrites existing)
- Color int `json:"color"` // The color the role should have (as a decimal, not hex)
- Hoist bool `json:"hoist"` // Whether to display the role's users separately
- Permissions int64 `json:"permissions,string"` // The overall permissions number of the role (overwrites existing)
- Mentionable bool `json:"mentionable"` // Whether this role is mentionable
- }{name, color, hoist, perm, mention}
-
body, err := s.RequestWithBucketID("PATCH", EndpointGuildRole(guildID, roleID), data, EndpointGuildRole(guildID, ""))
if err != nil {
return
@@ -1159,12 +1268,10 @@ func (s *Session) GuildEmbed(guildID string) (st *GuildEmbed, err error) {
return
}
-// GuildEmbedEdit returns the embed for a Guild.
+// GuildEmbedEdit edits the embed of a Guild.
// guildID : The ID of a Guild.
-func (s *Session) GuildEmbedEdit(guildID string, enabled bool, channelID string) (err error) {
-
- data := GuildEmbed{enabled, channelID}
-
+// data : New GuildEmbed data.
+func (s *Session) GuildEmbedEdit(guildID string, data *GuildEmbed) (err error) {
_, err = s.RequestWithBucketID("PATCH", EndpointGuildEmbed(guildID), data, EndpointGuildEmbed(guildID))
return
}
@@ -1218,19 +1325,24 @@ func (s *Session) GuildEmojis(guildID string) (emoji []*Emoji, err error) {
return
}
-// GuildEmojiCreate creates a new emoji
-// guildID : The ID of a Guild.
-// name : The Name of the Emoji.
-// image : The base64 encoded emoji image, has to be smaller than 256KB.
-// roles : The roles for which this emoji will be whitelisted, can be nil.
-func (s *Session) GuildEmojiCreate(guildID, name, image string, roles []string) (emoji *Emoji, err error) {
+// GuildEmoji returns specified emoji.
+// guildID : The ID of a Guild
+// emojiID : The ID of an Emoji to retrieve
+func (s *Session) GuildEmoji(guildID, emojiID string) (emoji *Emoji, err error) {
+ var body []byte
+ body, err = s.RequestWithBucketID("GET", EndpointGuildEmoji(guildID, emojiID), nil, EndpointGuildEmoji(guildID, emojiID))
+ if err != nil {
+ return
+ }
- data := struct {
- Name string `json:"name"`
- Image string `json:"image"`
- Roles []string `json:"roles,omitempty"`
- }{name, image, roles}
+ err = unmarshal(body, &emoji)
+ return
+}
+// GuildEmojiCreate creates a new Emoji.
+// guildID : The ID of a Guild.
+// data : New Emoji data.
+func (s *Session) GuildEmojiCreate(guildID string, data *EmojiParams) (emoji *Emoji, err error) {
body, err := s.RequestWithBucketID("POST", EndpointGuildEmojis(guildID), data, EndpointGuildEmojis(guildID))
if err != nil {
return
@@ -1240,18 +1352,11 @@ func (s *Session) GuildEmojiCreate(guildID, name, image string, roles []string)
return
}
-// GuildEmojiEdit modifies an emoji
+// GuildEmojiEdit modifies and returns updated Emoji.
// guildID : The ID of a Guild.
// emojiID : The ID of an Emoji.
-// name : The Name of the Emoji.
-// roles : The roles for which this emoji will be whitelisted, can be nil.
-func (s *Session) GuildEmojiEdit(guildID, emojiID, name string, roles []string) (emoji *Emoji, err error) {
-
- data := struct {
- Name string `json:"name"`
- Roles []string `json:"roles,omitempty"`
- }{name, roles}
-
+// data : Updated Emoji data.
+func (s *Session) GuildEmojiEdit(guildID, emojiID string, data *EmojiParams) (emoji *Emoji, err error) {
body, err := s.RequestWithBucketID("PATCH", EndpointGuildEmoji(guildID, emojiID), data, EndpointGuildEmojis(guildID))
if err != nil {
return
@@ -1317,16 +1422,9 @@ func (s *Session) GuildTemplates(guildID string) (st []*GuildTemplate, err error
}
// GuildTemplateCreate creates a template for the guild
-// guildID: The ID of the guild
-// name: The name of the template (1-100 characters)
-// description: The description for the template (0-120 characters)
-func (s *Session) GuildTemplateCreate(guildID, name, description string) (st *GuildTemplate) {
-
- data := struct {
- Name string `json:"name"`
- Description string `json:"description"`
- }{name, description}
-
+// guildID : The ID of the guild
+// data : Template metadata
+func (s *Session) GuildTemplateCreate(guildID string, data *GuildTemplateParams) (st *GuildTemplate) {
body, err := s.RequestWithBucketID("POST", EndpointGuildTemplates(guildID), data, EndpointGuildTemplates(guildID))
if err != nil {
return
@@ -1346,16 +1444,10 @@ func (s *Session) GuildTemplateSync(guildID, templateCode string) (err error) {
}
// GuildTemplateEdit modifies the template's metadata
-// guildID: The ID of the guild
-// templateCode: The code of the template
-// name: The name of the template (1-100 characters)
-// description: The description for the template (0-120 characters)
-func (s *Session) GuildTemplateEdit(guildID, templateCode, name, description string) (st *GuildTemplate, err error) {
-
- data := struct {
- Name string `json:"name,omitempty"`
- Description string `json:"description,omitempty"`
- }{name, description}
+// guildID : The ID of the guild
+// templateCode : The code of the template
+// data : New template metadata
+func (s *Session) GuildTemplateEdit(guildID, templateCode string, data *GuildTemplateParams) (st *GuildTemplate, err error) {
body, err := s.RequestWithBucketID("PATCH", EndpointGuildTemplateSync(guildID, templateCode), data, EndpointGuildTemplateSync(guildID, ""))
if err != nil {
@@ -1391,19 +1483,10 @@ func (s *Session) Channel(channelID string) (st *Channel, err error) {
return
}
-// ChannelEdit edits the given channel
-// channelID : The ID of a Channel
-// name : The new name to assign the channel.
-func (s *Session) ChannelEdit(channelID, name string) (*Channel, error) {
- return s.ChannelEditComplex(channelID, &ChannelEdit{
- Name: name,
- })
-}
-
-// ChannelEditComplex edits an existing channel, replacing the parameters entirely with ChannelEdit struct
-// channelID : The ID of a Channel
-// data : The channel struct to send
-func (s *Session) ChannelEditComplex(channelID string, data *ChannelEdit) (st *Channel, err error) {
+// ChannelEdit edits the given channel and returns the updated Channel data.
+// channelID : The ID of a Channel.
+// data : New Channel data.
+func (s *Session) ChannelEdit(channelID string, data *ChannelEdit) (st *Channel, err error) {
body, err := s.RequestWithBucketID("PATCH", EndpointChannel(channelID), data, EndpointChannel(channelID))
if err != nil {
return
@@ -1411,6 +1494,15 @@ func (s *Session) ChannelEditComplex(channelID string, data *ChannelEdit) (st *C
err = unmarshal(body, &st)
return
+
+}
+
+// ChannelEditComplex edits an existing channel, replacing the parameters entirely with ChannelEdit struct
+// NOTE: deprecated, use ChannelEdit instead
+// channelID : The ID of a Channel
+// data : The channel struct to send
+func (s *Session) ChannelEditComplex(channelID string, data *ChannelEdit) (st *Channel, err error) {
+ return s.ChannelEdit(channelID, data)
}
// ChannelDelete deletes the given channel
@@ -1588,6 +1680,28 @@ func (s *Session) ChannelMessageSendReply(channelID string, content string, refe
})
}
+// ChannelMessageSendEmbedReply sends a message to the given channel with reference data and embedded data.
+// channelID : The ID of a Channel.
+// embed : The embed data to send.
+// reference : The message reference to send.
+func (s *Session) ChannelMessageSendEmbedReply(channelID string, embed *MessageEmbed, reference *MessageReference) (*Message, error) {
+ return s.ChannelMessageSendEmbedsReply(channelID, []*MessageEmbed{embed}, reference)
+}
+
+// ChannelMessageSendEmbedsReply sends a message to the given channel with reference data and multiple embedded data.
+// channelID : The ID of a Channel.
+// embeds : The embeds data to send.
+// reference : The message reference to send.
+func (s *Session) ChannelMessageSendEmbedsReply(channelID string, embeds []*MessageEmbed, reference *MessageReference) (*Message, error) {
+ if reference == nil {
+ return nil, fmt.Errorf("reply attempted with nil message reference")
+ }
+ return s.ChannelMessageSendComplex(channelID, &MessageSend{
+ Embeds: embeds,
+ Reference: reference,
+ })
+}
+
// ChannelMessageEdit edits an existing message, replacing it entirely with
// the given content.
// channelID : The ID of a Channel
@@ -1851,6 +1965,37 @@ func (s *Session) InviteWithCounts(inviteID string) (st *Invite, err error) {
return
}
+// InviteComplex returns an Invite structure of the given invite including specified fields.
+// inviteID : The invite code
+// guildScheduledEventID : If specified, includes specified guild scheduled event.
+// withCounts : Whether to include approximate member counts or not
+// withExpiration : Whether to include expiration time or not
+func (s *Session) InviteComplex(inviteID, guildScheduledEventID string, withCounts, withExpiration bool) (st *Invite, err error) {
+ endpoint := EndpointInvite(inviteID)
+ v := url.Values{}
+ if guildScheduledEventID != "" {
+ v.Set("guild_scheduled_event_id", guildScheduledEventID)
+ }
+ if withCounts {
+ v.Set("with_counts", "true")
+ }
+ if withExpiration {
+ v.Set("with_expiration", "true")
+ }
+
+ if len(v) != 0 {
+ endpoint += "?" + v.Encode()
+ }
+
+ body, err := s.RequestWithBucketID("GET", endpoint, nil, EndpointInvite(""))
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
// InviteDelete deletes an existing invite
// inviteID : the code of an invite
func (s *Session) InviteDelete(inviteID string) (st *Invite, err error) {
@@ -2158,7 +2303,7 @@ func (s *Session) WebhookMessage(webhookID, token, messageID string) (message *M
return
}
- err = json.Unmarshal(body, &message)
+ err = Unmarshal(body, &message)
return
}
@@ -2207,7 +2352,7 @@ func (s *Session) WebhookMessageDelete(webhookID, token, messageID string) (err
// MessageReactionAdd creates an emoji reaction to a message.
// channelID : The channel ID.
// messageID : The message ID.
-// emojiID : Either the unicode emoji for the reaction, or a guild emoji identifier.
+// emojiID : Either the unicode emoji for the reaction, or a guild emoji identifier in name:id format (e.g. "hello:1234567654321")
func (s *Session) MessageReactionAdd(channelID, messageID, emojiID string) error {
// emoji such as #⃣ need to have # escaped
@@ -2620,7 +2765,7 @@ func (s *Session) ApplicationCommands(appID, guildID string) (cmd []*Application
endpoint = EndpointApplicationGuildCommands(appID, guildID)
}
- body, err := s.RequestWithBucketID("GET", endpoint, nil, endpoint)
+ body, err := s.RequestWithBucketID("GET", endpoint+"?with_localizations=true", nil, "GET "+endpoint)
if err != nil {
return
}
@@ -2668,6 +2813,8 @@ func (s *Session) ApplicationCommandPermissions(appID, guildID, cmdID string) (p
// guildID : The guild ID containing the application command
// cmdID : The command ID to edit the permissions of
// permissions : An object containing a list of permissions for the application command
+//
+// NOTE: Requires OAuth2 token with applications.commands.permissions.update scope
func (s *Session) ApplicationCommandPermissionsEdit(appID, guildID, cmdID string, permissions *ApplicationCommandPermissionsList) (err error) {
endpoint := EndpointApplicationCommandPermissions(appID, guildID, cmdID)
@@ -2679,6 +2826,8 @@ func (s *Session) ApplicationCommandPermissionsEdit(appID, guildID, cmdID string
// appID : The Application ID
// guildID : The guild ID to batch edit commands of
// permissions : A list of permissions paired with a command ID, guild ID, and application ID per application command
+//
+// NOTE: This endpoint has been disabled with updates to command permissions (Permissions v2). Please use ApplicationCommandPermissionsEdit instead.
func (s *Session) ApplicationCommandPermissionsBatchEdit(appID, guildID string, permissions []*GuildApplicationCommandPermissions) (err error) {
endpoint := EndpointApplicationCommandsGuildPermissions(appID, guildID)
@@ -2687,10 +2836,9 @@ func (s *Session) ApplicationCommandPermissionsBatchEdit(appID, guildID string,
}
// InteractionRespond creates the response to an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
// resp : Response message data.
-func (s *Session) InteractionRespond(interaction *Interaction, resp *InteractionResponse) (err error) {
+func (s *Session) InteractionRespond(interaction *Interaction, resp *InteractionResponse) error {
endpoint := EndpointInteractionResponse(interaction.ID, interaction.Token)
if resp.Data != nil && len(resp.Data.Files) > 0 {
@@ -2700,32 +2848,30 @@ func (s *Session) InteractionRespond(interaction *Interaction, resp *Interaction
}
_, err = s.request("POST", endpoint, contentType, body, endpoint, 0)
- } else {
- _, err = s.RequestWithBucketID("POST", endpoint, *resp, endpoint)
+ return err
}
+
+ _, err := s.RequestWithBucketID("POST", endpoint, *resp, endpoint)
return err
}
// InteractionResponse gets the response to an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
-func (s *Session) InteractionResponse(appID string, interaction *Interaction) (*Message, error) {
- return s.WebhookMessage(appID, interaction.Token, "@original")
+func (s *Session) InteractionResponse(interaction *Interaction) (*Message, error) {
+ return s.WebhookMessage(interaction.AppID, interaction.Token, "@original")
}
// InteractionResponseEdit edits the response to an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
// newresp : Updated response message data.
-func (s *Session) InteractionResponseEdit(appID string, interaction *Interaction, newresp *WebhookEdit) (*Message, error) {
- return s.WebhookMessageEdit(appID, interaction.Token, "@original", newresp)
+func (s *Session) InteractionResponseEdit(interaction *Interaction, newresp *WebhookEdit) (*Message, error) {
+ return s.WebhookMessageEdit(interaction.AppID, interaction.Token, "@original", newresp)
}
// InteractionResponseDelete deletes the response to an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
-func (s *Session) InteractionResponseDelete(appID string, interaction *Interaction) error {
- endpoint := EndpointInteractionResponseActions(appID, interaction.Token)
+func (s *Session) InteractionResponseDelete(interaction *Interaction) error {
+ endpoint := EndpointInteractionResponseActions(interaction.AppID, interaction.Token)
_, err := s.RequestWithBucketID("DELETE", endpoint, nil, endpoint)
@@ -2733,29 +2879,76 @@ func (s *Session) InteractionResponseDelete(appID string, interaction *Interacti
}
// FollowupMessageCreate creates the followup message for an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
// wait : Waits for server confirmation of message send and ensures that the return struct is populated (it is nil otherwise)
// data : Data of the message to send.
-func (s *Session) FollowupMessageCreate(appID string, interaction *Interaction, wait bool, data *WebhookParams) (*Message, error) {
- return s.WebhookExecute(appID, interaction.Token, wait, data)
+func (s *Session) FollowupMessageCreate(interaction *Interaction, wait bool, data *WebhookParams) (*Message, error) {
+ return s.WebhookExecute(interaction.AppID, interaction.Token, wait, data)
}
// FollowupMessageEdit edits a followup message of an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
// messageID : The followup message ID.
// data : Data to update the message
-func (s *Session) FollowupMessageEdit(appID string, interaction *Interaction, messageID string, data *WebhookEdit) (*Message, error) {
- return s.WebhookMessageEdit(appID, interaction.Token, messageID, data)
+func (s *Session) FollowupMessageEdit(interaction *Interaction, messageID string, data *WebhookEdit) (*Message, error) {
+ return s.WebhookMessageEdit(interaction.AppID, interaction.Token, messageID, data)
}
// FollowupMessageDelete deletes a followup message of an interaction.
-// appID : The application ID.
// interaction : Interaction instance.
// messageID : The followup message ID.
-func (s *Session) FollowupMessageDelete(appID string, interaction *Interaction, messageID string) error {
- return s.WebhookMessageDelete(appID, interaction.Token, messageID)
+func (s *Session) FollowupMessageDelete(interaction *Interaction, messageID string) error {
+ return s.WebhookMessageDelete(interaction.AppID, interaction.Token, messageID)
+}
+
+// ------------------------------------------------------------------------------------------------
+// Functions specific to stage instances
+// ------------------------------------------------------------------------------------------------
+
+// StageInstanceCreate creates and returns a new Stage instance associated to a Stage channel.
+// data : Parameters needed to create a stage instance.
+// data : The data of the Stage instance to create
+func (s *Session) StageInstanceCreate(data *StageInstanceParams) (si *StageInstance, err error) {
+ body, err := s.RequestWithBucketID("POST", EndpointStageInstances, data, EndpointStageInstances)
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &si)
+ return
+}
+
+// StageInstance will retrieve a Stage instance by ID of the Stage channel.
+// channelID : The ID of the Stage channel
+func (s *Session) StageInstance(channelID string) (si *StageInstance, err error) {
+ body, err := s.RequestWithBucketID("GET", EndpointStageInstance(channelID), nil, EndpointStageInstance(channelID))
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &si)
+ return
+}
+
+// StageInstanceEdit will edit a Stage instance by ID of the Stage channel.
+// channelID : The ID of the Stage channel
+// data : The data to edit the Stage instance
+func (s *Session) StageInstanceEdit(channelID string, data *StageInstanceParams) (si *StageInstance, err error) {
+
+ body, err := s.RequestWithBucketID("PATCH", EndpointStageInstance(channelID), data, EndpointStageInstance(channelID))
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &si)
+ return
+}
+
+// StageInstanceDelete will delete a Stage instance by ID of the Stage channel.
+// channelID : The ID of the Stage channel
+func (s *Session) StageInstanceDelete(channelID string) (err error) {
+ _, err = s.RequestWithBucketID("DELETE", EndpointStageInstance(channelID), nil, EndpointStageInstance(channelID))
+ return
}
// ------------------------------------------------------------------------------------------------
@@ -2869,3 +3062,80 @@ func (s *Session) GuildScheduledEventUsers(guildID, eventID string, limit int, w
err = unmarshal(body, &st)
return
}
+
+// ----------------------------------------------------------------------
+// Functions specific to auto moderation
+// ----------------------------------------------------------------------
+
+// AutoModerationRules returns a list of auto moderation rules.
+// guildID : ID of the guild
+func (s *Session) AutoModerationRules(guildID string) (st []*AutoModerationRule, err error) {
+ endpoint := EndpointGuildAutoModerationRules(guildID)
+
+ var body []byte
+ body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint)
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
+// AutoModerationRule returns an auto moderation rule.
+// guildID : ID of the guild
+// ruleID : ID of the auto moderation rule
+func (s *Session) AutoModerationRule(guildID, ruleID string) (st *AutoModerationRule, err error) {
+ endpoint := EndpointGuildAutoModerationRule(guildID, ruleID)
+
+ var body []byte
+ body, err = s.RequestWithBucketID("GET", endpoint, nil, endpoint)
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
+// AutoModerationRuleCreate creates an auto moderation rule with the given data and returns it.
+// guildID : ID of the guild
+// rule : Rule data
+func (s *Session) AutoModerationRuleCreate(guildID string, rule *AutoModerationRule) (st *AutoModerationRule, err error) {
+ endpoint := EndpointGuildAutoModerationRules(guildID)
+
+ var body []byte
+ body, err = s.RequestWithBucketID("POST", endpoint, rule, endpoint)
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
+// AutoModerationRuleEdit edits and returns the updated auto moderation rule.
+// guildID : ID of the guild
+// ruleID : ID of the auto moderation rule
+// rule : New rule data
+func (s *Session) AutoModerationRuleEdit(guildID, ruleID string, rule *AutoModerationRule) (st *AutoModerationRule, err error) {
+ endpoint := EndpointGuildAutoModerationRule(guildID, ruleID)
+
+ var body []byte
+ body, err = s.RequestWithBucketID("PATCH", endpoint, rule, endpoint)
+ if err != nil {
+ return
+ }
+
+ err = unmarshal(body, &st)
+ return
+}
+
+// AutoModerationRuleDelete deletes an auto moderation rule.
+// guildID : ID of the guild
+// ruleID : ID of the auto moderation rule
+func (s *Session) AutoModerationRuleDelete(guildID, ruleID string) (err error) {
+ endpoint := EndpointGuildAutoModerationRule(guildID, ruleID)
+ _, err = s.RequestWithBucketID("DELETE", endpoint, nil, endpoint)
+ return
+}