From 7d7206b01bb53b2df6999691c19f2358a728b57a Mon Sep 17 00:00:00 2001 From: Pierce Date: Tue, 11 May 2021 23:51:33 -0400 Subject: [PATCH] Bulk command overwrite (#926) * add session.ApplicationCommandBulkOverwrite * change ApplicationCommandBulkOverwrite to take a guildID * formatting * add omitempty to ID of ApplicationCommand --- interactions.go | 2 +- restapi.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/interactions.go b/interactions.go index 201baa8..d68b2b9 100644 --- a/interactions.go +++ b/interactions.go @@ -15,7 +15,7 @@ const InteractionDeadline = time.Second * 3 // ApplicationCommand represents an application's slash command. type ApplicationCommand struct { - ID string `json:"id"` + ID string `json:"id,omitempty"` ApplicationID string `json:"application_id,omitempty"` Name string `json:"name"` Description string `json:"description,omitempty"` diff --git a/restapi.go b/restapi.go index 8afc1e4..755e4b7 100644 --- a/restapi.go +++ b/restapi.go @@ -2472,6 +2472,25 @@ func (s *Session) ApplicationCommandEdit(appID, guildID, cmdID string, cmd *Appl return } +// ApplicationCommandBulkOverwrite Creates commands overwriting existing commands. Returns a list of commands. +// appID : The application ID. +// commands : The commands to create. +func (s *Session) ApplicationCommandBulkOverwrite(appID string, guildID string, commands []*ApplicationCommand) (createdCommands []*ApplicationCommand, err error) { + endpoint := EndpointApplicationGlobalCommands(appID) + if guildID != "" { + endpoint = EndpointApplicationGuildCommands(appID, guildID) + } + + body, err := s.RequestWithBucketID("PUT", endpoint, commands, endpoint) + if err != nil { + return + } + + err = unmarshal(body, &createdCommands) + + return +} + // ApplicationCommandDelete deletes application command by ID. // appID : The application ID. // cmdID : Application command ID to delete.