discord: Correct BulkOverwriteGuildCommands parameters (#301)

This commit is contained in:
PL Pery 2022-01-03 22:38:38 +01:00 committed by GitHub
parent 9cd0c7ed28
commit 11432e426c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 21 deletions

View File

@ -107,11 +107,8 @@ func main() {
},
}
for _, command := range newCommands {
_, err := s.CreateGuildCommand(app.ID, guildID, command)
if err != nil {
log.Fatalln("failed to create guild command:", err)
}
if _, err := s.BulkOverwriteGuildCommands(app.ID, guildID, newCommands); err != nil {
log.Fatalln("failed to create guild command:", err)
}
// Block forever.

View File

@ -28,7 +28,6 @@ func main() {
if err != nil {
log.Fatalln("failed to get application ID:", err)
}
appID := app.ID
s.AddHandler(func(e *gateway.InteractionCreateEvent) {
var resp api.InteractionResponse
@ -108,7 +107,7 @@ func main() {
log.Println("Gateway connected. Getting all guild commands.")
commands, err := s.GuildCommands(appID, guildID)
commands, err := s.GuildCommands(app.ID, guildID)
if err != nil {
log.Fatalln("failed to get guild commands:", err)
}
@ -126,11 +125,8 @@ func main() {
log.Println("Creating guild commands...")
for _, command := range newCommands {
_, err := s.CreateGuildCommand(appID, guildID, command)
if err != nil {
log.Fatalln("failed to create guild command:", err)
}
if _, err := s.BulkOverwriteGuildCommands(app.ID, guildID, newCommands); err != nil {
log.Fatalln("failed to create guild command:", err)
}
log.Println("Guild commands created. Bot is ready.")

View File

@ -68,11 +68,8 @@ func main() {
},
}
for _, command := range newCommands {
_, err := s.CreateGuildCommand(app.ID, guildID, command)
if err != nil {
log.Fatalln("failed to create guild command:", err)
}
if _, err := s.BulkOverwriteGuildCommands(app.ID, guildID, newCommands); err != nil {
log.Fatalln("failed to create guild command:", err)
}
// Block forever.

View File

@ -121,7 +121,7 @@ func (c *Client) DeleteCommand(appID discord.AppID, commandID discord.CommandID)
// Commands that do not already exist will count toward daily application
// command create limits.
func (c *Client) BulkOverwriteCommands(
appID discord.AppID, commands []discord.Command) ([]discord.Command, error) {
appID discord.AppID, commands []CreateCommandData) ([]discord.Command, error) {
var cmds []discord.Command
return cmds, c.RequestJSON(
@ -194,7 +194,7 @@ func (c *Client) DeleteGuildCommand(
// overwriting existing commands that are registered for the guild.
func (c *Client) BulkOverwriteGuildCommands(
appID discord.AppID,
guildID discord.GuildID, commands []discord.Command) ([]discord.Command, error) {
guildID discord.GuildID, commands []CreateCommandData) ([]discord.Command, error) {
var cmds []discord.Command
return cmds, c.RequestJSON(

View File

@ -102,7 +102,8 @@ func (c *Client) RespondInteraction(
id discord.InteractionID, token string, resp InteractionResponse) error {
if resp.Data != nil {
if resp.Type == MessageInteractionWithSource {
switch resp.Type {
case MessageInteractionWithSource:
// A new message is being created, make sure none of the fields
// are null or empty.
if (resp.Data.Content == nil || resp.Data.Content.Val == "") &&
@ -110,7 +111,7 @@ func (c *Client) RespondInteraction(
len(resp.Data.Files) == 0 {
return ErrEmptyMessage
}
} else if resp.Type == UpdateMessage {
case UpdateMessage:
// A component is being updated. We therefore don't know what
// fields are filled. The only thing we can check is if content,
// embeds and files are null.