Application commands: Permissions v2 (#1075)

* feat(interactions): default command permissions

* feat: add ApplicationCommandPermissionTypeChannel

* feat: add deprecation and oauth2 scope comments

* feat(interactions): add GuildAllChannelsID function

* feat(examples/slash_commands): application command permissions

* feat(events): add ApplicationCommandPermissionsUpdate

* feat: add AuditLogActionApplicationCommandPermissionUpdate

* feat(interactions#GuildAllChannelsID): use strconv instead of math/big

* feat(interactions#GuildAllChannelsID): error handling

* feat: cosmetic changes

* fix(examples/slash_commands): handle error returned by GuildAllChannelsID

* fix: typo

* fix: typo
This commit is contained in:
Fedor Lapshin 2022-04-29 00:23:07 +03:00 committed by GitHub
parent cd95ccc2d3
commit 9e0783c37f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 273 additions and 125 deletions

View file

@ -7,69 +7,90 @@ package discordgo
// Event type values are used to match the events returned by Discord. // Event type values are used to match the events returned by Discord.
// EventTypes surrounded by __ are synthetic and are internal to DiscordGo. // EventTypes surrounded by __ are synthetic and are internal to DiscordGo.
const ( const (
channelCreateEventType = "CHANNEL_CREATE" applicationCommandPermissionsUpdateEventType = "APPLICATION_COMMAND_PERMISSIONS_UPDATE"
channelDeleteEventType = "CHANNEL_DELETE" channelCreateEventType = "CHANNEL_CREATE"
channelPinsUpdateEventType = "CHANNEL_PINS_UPDATE" channelDeleteEventType = "CHANNEL_DELETE"
channelUpdateEventType = "CHANNEL_UPDATE" channelPinsUpdateEventType = "CHANNEL_PINS_UPDATE"
connectEventType = "__CONNECT__" channelUpdateEventType = "CHANNEL_UPDATE"
disconnectEventType = "__DISCONNECT__" connectEventType = "__CONNECT__"
eventEventType = "__EVENT__" disconnectEventType = "__DISCONNECT__"
guildBanAddEventType = "GUILD_BAN_ADD" eventEventType = "__EVENT__"
guildBanRemoveEventType = "GUILD_BAN_REMOVE" guildBanAddEventType = "GUILD_BAN_ADD"
guildCreateEventType = "GUILD_CREATE" guildBanRemoveEventType = "GUILD_BAN_REMOVE"
guildDeleteEventType = "GUILD_DELETE" guildCreateEventType = "GUILD_CREATE"
guildEmojisUpdateEventType = "GUILD_EMOJIS_UPDATE" guildDeleteEventType = "GUILD_DELETE"
guildIntegrationsUpdateEventType = "GUILD_INTEGRATIONS_UPDATE" guildEmojisUpdateEventType = "GUILD_EMOJIS_UPDATE"
guildMemberAddEventType = "GUILD_MEMBER_ADD" guildIntegrationsUpdateEventType = "GUILD_INTEGRATIONS_UPDATE"
guildMemberRemoveEventType = "GUILD_MEMBER_REMOVE" guildMemberAddEventType = "GUILD_MEMBER_ADD"
guildMemberUpdateEventType = "GUILD_MEMBER_UPDATE" guildMemberRemoveEventType = "GUILD_MEMBER_REMOVE"
guildMembersChunkEventType = "GUILD_MEMBERS_CHUNK" guildMemberUpdateEventType = "GUILD_MEMBER_UPDATE"
guildRoleCreateEventType = "GUILD_ROLE_CREATE" guildMembersChunkEventType = "GUILD_MEMBERS_CHUNK"
guildRoleDeleteEventType = "GUILD_ROLE_DELETE" guildRoleCreateEventType = "GUILD_ROLE_CREATE"
guildRoleUpdateEventType = "GUILD_ROLE_UPDATE" guildRoleDeleteEventType = "GUILD_ROLE_DELETE"
guildStageInstanceCreateEventType = "STAGE_INSTANCE_CREATE" guildRoleUpdateEventType = "GUILD_ROLE_UPDATE"
guildStageInstanceUpdateEventType = "STAGE_INSTANCE_UPDATE" guildScheduledEventCreateEventType = "GUILD_SCHEDULED_EVENT_CREATE"
guildStageInstanceDeleteEventType = "STAGE_INSTANCE_DELETE" guildScheduledEventDeleteEventType = "GUILD_SCHEDULED_EVENT_DELETE"
guildScheduledEventCreateEventType = "GUILD_SCHEDULED_EVENT_CREATE" guildScheduledEventUpdateEventType = "GUILD_SCHEDULED_EVENT_UPDATE"
guildScheduledEventDeleteEventType = "GUILD_SCHEDULED_EVENT_DELETE" guildScheduledEventUserAddEventType = "GUILD_SCHEDULED_EVENT_USER_ADD"
guildScheduledEventUpdateEventType = "GUILD_SCHEDULED_EVENT_UPDATE" guildScheduledEventUserRemoveEventType = "GUILD_SCHEDULED_EVENT_USER_REMOVE"
guildScheduledEventUserAddEventType = "GUILD_SCHEDULED_EVENT_USER_ADD" guildUpdateEventType = "GUILD_UPDATE"
guildScheduledEventUserRemoveEventType = "GUILD_SCHEDULED_EVENT_USER_REMOVE" interactionCreateEventType = "INTERACTION_CREATE"
guildUpdateEventType = "GUILD_UPDATE" inviteCreateEventType = "INVITE_CREATE"
interactionCreateEventType = "INTERACTION_CREATE" inviteDeleteEventType = "INVITE_DELETE"
inviteCreateEventType = "INVITE_CREATE" messageAckEventType = "MESSAGE_ACK"
inviteDeleteEventType = "INVITE_DELETE" messageCreateEventType = "MESSAGE_CREATE"
messageAckEventType = "MESSAGE_ACK" messageDeleteEventType = "MESSAGE_DELETE"
messageCreateEventType = "MESSAGE_CREATE" messageDeleteBulkEventType = "MESSAGE_DELETE_BULK"
messageDeleteEventType = "MESSAGE_DELETE" messageReactionAddEventType = "MESSAGE_REACTION_ADD"
messageDeleteBulkEventType = "MESSAGE_DELETE_BULK" messageReactionRemoveEventType = "MESSAGE_REACTION_REMOVE"
messageReactionAddEventType = "MESSAGE_REACTION_ADD" messageReactionRemoveAllEventType = "MESSAGE_REACTION_REMOVE_ALL"
messageReactionRemoveEventType = "MESSAGE_REACTION_REMOVE" messageUpdateEventType = "MESSAGE_UPDATE"
messageReactionRemoveAllEventType = "MESSAGE_REACTION_REMOVE_ALL" presenceUpdateEventType = "PRESENCE_UPDATE"
messageUpdateEventType = "MESSAGE_UPDATE" presencesReplaceEventType = "PRESENCES_REPLACE"
presenceUpdateEventType = "PRESENCE_UPDATE" rateLimitEventType = "__RATE_LIMIT__"
presencesReplaceEventType = "PRESENCES_REPLACE" readyEventType = "READY"
rateLimitEventType = "__RATE_LIMIT__" relationshipAddEventType = "RELATIONSHIP_ADD"
readyEventType = "READY" relationshipRemoveEventType = "RELATIONSHIP_REMOVE"
relationshipAddEventType = "RELATIONSHIP_ADD" resumedEventType = "RESUMED"
relationshipRemoveEventType = "RELATIONSHIP_REMOVE" stageInstanceEventCreateEventType = "STAGE_INSTANCE_EVENT_CREATE"
resumedEventType = "RESUMED" stageInstanceEventDeleteEventType = "STAGE_INSTANCE_EVENT_DELETE"
threadCreateEventType = "THREAD_CREATE" stageInstanceEventUpdateEventType = "STAGE_INSTANCE_EVENT_UPDATE"
threadDeleteEventType = "THREAD_DELETE" threadCreateEventType = "THREAD_CREATE"
threadListSyncEventType = "THREAD_LIST_SYNC" threadDeleteEventType = "THREAD_DELETE"
threadMemberUpdateEventType = "THREAD_MEMBER_UPDATE" threadListSyncEventType = "THREAD_LIST_SYNC"
threadMembersUpdateEventType = "THREAD_MEMBERS_UPDATE" threadMemberUpdateEventType = "THREAD_MEMBER_UPDATE"
threadUpdateEventType = "THREAD_UPDATE" threadMembersUpdateEventType = "THREAD_MEMBERS_UPDATE"
typingStartEventType = "TYPING_START" threadUpdateEventType = "THREAD_UPDATE"
userGuildSettingsUpdateEventType = "USER_GUILD_SETTINGS_UPDATE" typingStartEventType = "TYPING_START"
userNoteUpdateEventType = "USER_NOTE_UPDATE" userGuildSettingsUpdateEventType = "USER_GUILD_SETTINGS_UPDATE"
userSettingsUpdateEventType = "USER_SETTINGS_UPDATE" userNoteUpdateEventType = "USER_NOTE_UPDATE"
userUpdateEventType = "USER_UPDATE" userSettingsUpdateEventType = "USER_SETTINGS_UPDATE"
voiceServerUpdateEventType = "VOICE_SERVER_UPDATE" userUpdateEventType = "USER_UPDATE"
voiceStateUpdateEventType = "VOICE_STATE_UPDATE" voiceServerUpdateEventType = "VOICE_SERVER_UPDATE"
webhooksUpdateEventType = "WEBHOOKS_UPDATE" voiceStateUpdateEventType = "VOICE_STATE_UPDATE"
webhooksUpdateEventType = "WEBHOOKS_UPDATE"
) )
// applicationCommandPermissionsUpdateEventHandler is an event handler for ApplicationCommandPermissionsUpdate events.
type applicationCommandPermissionsUpdateEventHandler func(*Session, *ApplicationCommandPermissionsUpdate)
// Type returns the event type for ApplicationCommandPermissionsUpdate events.
func (eh applicationCommandPermissionsUpdateEventHandler) Type() string {
return applicationCommandPermissionsUpdateEventType
}
// New returns a new instance of ApplicationCommandPermissionsUpdate.
func (eh applicationCommandPermissionsUpdateEventHandler) New() interface{} {
return &ApplicationCommandPermissionsUpdate{}
}
// Handle is the handler for ApplicationCommandPermissionsUpdate events.
func (eh applicationCommandPermissionsUpdateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*ApplicationCommandPermissionsUpdate); ok {
eh(s, t)
}
}
// channelCreateEventHandler is an event handler for ChannelCreate events. // channelCreateEventHandler is an event handler for ChannelCreate events.
type channelCreateEventHandler func(*Session, *ChannelCreate) type channelCreateEventHandler func(*Session, *ChannelCreate)
@ -455,66 +476,6 @@ func (eh guildRoleUpdateEventHandler) Handle(s *Session, i interface{}) {
} }
} }
// guildStageInstanceEventCreateHandler is an event handler for StageInstanceEventCreate events.
type guildStageInstanceEventCreateHandler func(*Session, *StageInstanceEventCreate)
// Type returns the event type for StageInstanceEventCreate events.
func (eh guildStageInstanceEventCreateHandler) Type() string {
return guildStageInstanceCreateEventType
}
// New returns a new instance of StageInstanceEventCreate.
func (eh guildStageInstanceEventCreateHandler) New() interface{} {
return &StageInstanceEventCreate{}
}
// Handle is the handler for StageInstanceEventCreate events.
func (eh guildStageInstanceEventCreateHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*StageInstanceEventCreate); ok {
eh(s, t)
}
}
// guildStageInstanceEventUpdateHandler is an event handler for StageInstanceEventUpdate events.
type guildStageInstanceEventUpdateHandler func(*Session, *StageInstanceEventUpdate)
// Type returns the event type for StageInstanceEventUpdate events.
func (eh guildStageInstanceEventUpdateHandler) Type() string {
return guildStageInstanceCreateEventType
}
// New returns a new instance of StageInstanceEventUpdate.
func (eh guildStageInstanceEventUpdateHandler) New() interface{} {
return &StageInstanceEventUpdate{}
}
// Handle is the handler for StageInstanceEventUpdate events.
func (eh guildStageInstanceEventUpdateHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*StageInstanceEventUpdate); ok {
eh(s, t)
}
}
// guildStageInstanceEventDeleteHandler is an event handler for StageInstanceEventDelete events.
type guildStageInstanceEventDeleteHandler func(*Session, *StageInstanceEventDelete)
// Type returns the event type for StageInstanceEventDelete events.
func (eh guildStageInstanceEventDeleteHandler) Type() string {
return guildStageInstanceCreateEventType
}
// New returns a new instance of StageInstanceEventDelete.
func (eh guildStageInstanceEventDeleteHandler) New() interface{} {
return &StageInstanceEventDelete{}
}
// Handle is the handler for StageInstanceEventDelete events.
func (eh guildStageInstanceEventDeleteHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*StageInstanceEventDelete); ok {
eh(s, t)
}
}
// guildScheduledEventCreateEventHandler is an event handler for GuildScheduledEventCreate events. // guildScheduledEventCreateEventHandler is an event handler for GuildScheduledEventCreate events.
type guildScheduledEventCreateEventHandler func(*Session, *GuildScheduledEventCreate) type guildScheduledEventCreateEventHandler func(*Session, *GuildScheduledEventCreate)
@ -990,6 +951,66 @@ func (eh resumedEventHandler) Handle(s *Session, i interface{}) {
} }
} }
// stageInstanceEventCreateEventHandler is an event handler for StageInstanceEventCreate events.
type stageInstanceEventCreateEventHandler func(*Session, *StageInstanceEventCreate)
// Type returns the event type for StageInstanceEventCreate events.
func (eh stageInstanceEventCreateEventHandler) Type() string {
return stageInstanceEventCreateEventType
}
// New returns a new instance of StageInstanceEventCreate.
func (eh stageInstanceEventCreateEventHandler) New() interface{} {
return &StageInstanceEventCreate{}
}
// Handle is the handler for StageInstanceEventCreate events.
func (eh stageInstanceEventCreateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*StageInstanceEventCreate); ok {
eh(s, t)
}
}
// stageInstanceEventDeleteEventHandler is an event handler for StageInstanceEventDelete events.
type stageInstanceEventDeleteEventHandler func(*Session, *StageInstanceEventDelete)
// Type returns the event type for StageInstanceEventDelete events.
func (eh stageInstanceEventDeleteEventHandler) Type() string {
return stageInstanceEventDeleteEventType
}
// New returns a new instance of StageInstanceEventDelete.
func (eh stageInstanceEventDeleteEventHandler) New() interface{} {
return &StageInstanceEventDelete{}
}
// Handle is the handler for StageInstanceEventDelete events.
func (eh stageInstanceEventDeleteEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*StageInstanceEventDelete); ok {
eh(s, t)
}
}
// stageInstanceEventUpdateEventHandler is an event handler for StageInstanceEventUpdate events.
type stageInstanceEventUpdateEventHandler func(*Session, *StageInstanceEventUpdate)
// Type returns the event type for StageInstanceEventUpdate events.
func (eh stageInstanceEventUpdateEventHandler) Type() string {
return stageInstanceEventUpdateEventType
}
// New returns a new instance of StageInstanceEventUpdate.
func (eh stageInstanceEventUpdateEventHandler) New() interface{} {
return &StageInstanceEventUpdate{}
}
// Handle is the handler for StageInstanceEventUpdate events.
func (eh stageInstanceEventUpdateEventHandler) Handle(s *Session, i interface{}) {
if t, ok := i.(*StageInstanceEventUpdate); ok {
eh(s, t)
}
}
// threadCreateEventHandler is an event handler for ThreadCreate events. // threadCreateEventHandler is an event handler for ThreadCreate events.
type threadCreateEventHandler func(*Session, *ThreadCreate) type threadCreateEventHandler func(*Session, *ThreadCreate)
@ -1274,6 +1295,8 @@ func handlerForInterface(handler interface{}) EventHandler {
switch v := handler.(type) { switch v := handler.(type) {
case func(*Session, interface{}): case func(*Session, interface{}):
return interfaceEventHandler(v) return interfaceEventHandler(v)
case func(*Session, *ApplicationCommandPermissionsUpdate):
return applicationCommandPermissionsUpdateEventHandler(v)
case func(*Session, *ChannelCreate): case func(*Session, *ChannelCreate):
return channelCreateEventHandler(v) return channelCreateEventHandler(v)
case func(*Session, *ChannelDelete): case func(*Session, *ChannelDelete):
@ -1362,6 +1385,12 @@ func handlerForInterface(handler interface{}) EventHandler {
return relationshipRemoveEventHandler(v) return relationshipRemoveEventHandler(v)
case func(*Session, *Resumed): case func(*Session, *Resumed):
return resumedEventHandler(v) return resumedEventHandler(v)
case func(*Session, *StageInstanceEventCreate):
return stageInstanceEventCreateEventHandler(v)
case func(*Session, *StageInstanceEventDelete):
return stageInstanceEventDeleteEventHandler(v)
case func(*Session, *StageInstanceEventUpdate):
return stageInstanceEventUpdateEventHandler(v)
case func(*Session, *ThreadCreate): case func(*Session, *ThreadCreate):
return threadCreateEventHandler(v) return threadCreateEventHandler(v)
case func(*Session, *ThreadDelete): case func(*Session, *ThreadDelete):
@ -1396,6 +1425,7 @@ func handlerForInterface(handler interface{}) EventHandler {
} }
func init() { func init() {
registerInterfaceProvider(applicationCommandPermissionsUpdateEventHandler(nil))
registerInterfaceProvider(channelCreateEventHandler(nil)) registerInterfaceProvider(channelCreateEventHandler(nil))
registerInterfaceProvider(channelDeleteEventHandler(nil)) registerInterfaceProvider(channelDeleteEventHandler(nil))
registerInterfaceProvider(channelPinsUpdateEventHandler(nil)) registerInterfaceProvider(channelPinsUpdateEventHandler(nil))
@ -1436,6 +1466,9 @@ func init() {
registerInterfaceProvider(relationshipAddEventHandler(nil)) registerInterfaceProvider(relationshipAddEventHandler(nil))
registerInterfaceProvider(relationshipRemoveEventHandler(nil)) registerInterfaceProvider(relationshipRemoveEventHandler(nil))
registerInterfaceProvider(resumedEventHandler(nil)) registerInterfaceProvider(resumedEventHandler(nil))
registerInterfaceProvider(stageInstanceEventCreateEventHandler(nil))
registerInterfaceProvider(stageInstanceEventDeleteEventHandler(nil))
registerInterfaceProvider(stageInstanceEventUpdateEventHandler(nil))
registerInterfaceProvider(threadCreateEventHandler(nil)) registerInterfaceProvider(threadCreateEventHandler(nil))
registerInterfaceProvider(threadDeleteEventHandler(nil)) registerInterfaceProvider(threadDeleteEventHandler(nil))
registerInterfaceProvider(threadListSyncEventHandler(nil)) registerInterfaceProvider(threadListSyncEventHandler(nil))

View file

@ -401,3 +401,8 @@ type InviteDelete struct {
GuildID string `json:"guild_id"` GuildID string `json:"guild_id"`
Code string `json:"code"` Code string `json:"code"`
} }
// ApplicationCommandPermissionsUpdate is the data for an ApplicationCommandPermissionsUpdate event
type ApplicationCommandPermissionsUpdate struct {
*GuildApplicationCommandPermissions
}

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"errors"
"flag" "flag"
"fmt" "fmt"
"log" "log"
@ -32,7 +33,9 @@ func init() {
} }
var ( var (
integerOptionMinValue = 1.0 integerOptionMinValue = 1.0
dmPermission = false
defaultMemberPermissions int64 = discordgo.PermissionManageServer
commands = []*discordgo.ApplicationCommand{ commands = []*discordgo.ApplicationCommand{
{ {
@ -42,6 +45,12 @@ var (
// of the command. // of the command.
Description: "Basic command", Description: "Basic command",
}, },
{
Name: "permission-overview",
Description: "Command for demonstration of default command permissions",
DefaultMemberPermissions: &defaultMemberPermissions,
DMPermission: &dmPermission,
},
{ {
Name: "basic-command-with-files", Name: "basic-command-with-files",
Description: "Basic command with files", Description: "Basic command with files",
@ -320,6 +329,84 @@ var (
}, },
}) })
}, },
"permission-overview": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
perms, err := s.ApplicationCommandPermissions(s.State.User.ID, i.GuildID, i.ApplicationCommandData().ID)
var restError *discordgo.RESTError
if errors.As(err, &restError) && restError.Message != nil && restError.Message.Code == discordgo.ErrCodeUnknownApplicationCommandPermissions {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: ":x: No permission overwrites",
},
})
return
} else if err != nil {
panic(err)
}
if err != nil {
panic(err)
}
format := "- %s %s\n"
channels := ""
users := ""
roles := ""
for _, o := range perms.Permissions {
emoji := "❌"
if o.Permission {
emoji = "☑"
}
switch o.Type {
case discordgo.ApplicationCommandPermissionTypeUser:
users += fmt.Sprintf(format, emoji, "<@!"+o.ID+">")
case discordgo.ApplicationCommandPermissionTypeChannel:
allChannels, _ := discordgo.GuildAllChannelsID(i.GuildID)
if o.ID == allChannels {
channels += fmt.Sprintf(format, emoji, "All channels")
} else {
channels += fmt.Sprintf(format, emoji, "<#"+o.ID+">")
}
case discordgo.ApplicationCommandPermissionTypeRole:
if o.ID == i.GuildID {
roles += fmt.Sprintf(format, emoji, "@everyone")
} else {
roles += fmt.Sprintf(format, emoji, "<@&"+o.ID+">")
}
}
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{
{
Title: "Permissions overview",
Description: "Overview of permissions for this command",
Fields: []*discordgo.MessageEmbedField{
{
Name: "Users",
Value: users,
},
{
Name: "Channels",
Value: channels,
},
{
Name: "Roles",
Value: roles,
},
},
},
},
AllowedMentions: &discordgo.MessageAllowedMentions{},
},
})
},
"subcommands": func(s *discordgo.Session, i *discordgo.InteractionCreate) { "subcommands": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
options := i.ApplicationCommandData().Options options := i.ApplicationCommandData().Options
content := "" content := ""

View file

@ -9,6 +9,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strconv"
"time" "time"
) )
@ -36,7 +37,10 @@ type ApplicationCommand struct {
Type ApplicationCommandType `json:"type,omitempty"` Type ApplicationCommandType `json:"type,omitempty"`
Name string `json:"name"` Name string `json:"name"`
NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"` NameLocalizations *map[Locale]string `json:"name_localizations,omitempty"`
DefaultPermission *bool `json:"default_permission,omitempty"` // NOTE: DefaultPermission will be soon deprecated. Use DefaultMemberPermissions and DMPermission instead.
DefaultPermission *bool `json:"default_permission,omitempty"`
DefaultMemberPermissions *int64 `json:"default_member_permissions,string,omitempty"`
DMPermission *bool `json:"dm_permission,omitempty"`
// NOTE: Chat commands only. Otherwise it mustn't be set. // NOTE: Chat commands only. Otherwise it mustn't be set.
@ -129,6 +133,18 @@ type ApplicationCommandPermissions struct {
Permission bool `json:"permission"` Permission bool `json:"permission"`
} }
// GuildAllChannelsID is a helper function which returns guild_id-1.
// It is used in ApplicationCommandPermissions to target all the channels within a guild.
func GuildAllChannelsID(guild string) (id string, err error) {
var v uint64
v, err = strconv.ParseUint(guild, 10, 64)
if err != nil {
return
}
return strconv.FormatUint(v-1, 10), nil
}
// ApplicationCommandPermissionsList represents a list of ApplicationCommandPermissions, needed for serializing to JSON. // ApplicationCommandPermissionsList represents a list of ApplicationCommandPermissions, needed for serializing to JSON.
type ApplicationCommandPermissionsList struct { type ApplicationCommandPermissionsList struct {
Permissions []*ApplicationCommandPermissions `json:"permissions"` Permissions []*ApplicationCommandPermissions `json:"permissions"`
@ -147,8 +163,9 @@ type ApplicationCommandPermissionType uint8
// Application command permission types. // Application command permission types.
const ( const (
ApplicationCommandPermissionTypeRole ApplicationCommandPermissionType = 1 ApplicationCommandPermissionTypeRole ApplicationCommandPermissionType = 1
ApplicationCommandPermissionTypeUser ApplicationCommandPermissionType = 2 ApplicationCommandPermissionTypeUser ApplicationCommandPermissionType = 2
ApplicationCommandPermissionTypeChannel ApplicationCommandPermissionType = 3
) )
// InteractionType indicates the type of an interaction event. // InteractionType indicates the type of an interaction event.

View file

@ -2840,6 +2840,8 @@ func (s *Session) ApplicationCommandPermissions(appID, guildID, cmdID string) (p
// guildID : The guild ID containing the application command // guildID : The guild ID containing the application command
// cmdID : The command ID to edit the permissions of // cmdID : The command ID to edit the permissions of
// permissions : An object containing a list of permissions for the application command // 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) { func (s *Session) ApplicationCommandPermissionsEdit(appID, guildID, cmdID string, permissions *ApplicationCommandPermissionsList) (err error) {
endpoint := EndpointApplicationCommandPermissions(appID, guildID, cmdID) endpoint := EndpointApplicationCommandPermissions(appID, guildID, cmdID)
@ -2851,6 +2853,8 @@ func (s *Session) ApplicationCommandPermissionsEdit(appID, guildID, cmdID string
// appID : The Application ID // appID : The Application ID
// guildID : The guild ID to batch edit commands of // 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 // 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) { func (s *Session) ApplicationCommandPermissionsBatchEdit(appID, guildID string, permissions []*GuildApplicationCommandPermissions) (err error) {
endpoint := EndpointApplicationCommandsGuildPermissions(appID, guildID) endpoint := EndpointApplicationCommandsGuildPermissions(appID, guildID)

View file

@ -1574,6 +1574,8 @@ const (
AuditLogActionThreadCreate AuditLogAction = 110 AuditLogActionThreadCreate AuditLogAction = 110
AuditLogActionThreadUpdate AuditLogAction = 111 AuditLogActionThreadUpdate AuditLogAction = 111
AuditLogActionThreadDelete AuditLogAction = 112 AuditLogActionThreadDelete AuditLogAction = 112
AuditLogActionApplicationCommandPermissionUpdate = 121
) )
// A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings. // A UserGuildSettingsChannelOverride stores data for a channel override for a users guild settings.