From 55f9725af10f1d8d3bfcf4b2045913d603e5581d Mon Sep 17 00:00:00 2001 From: Ava Affine Date: Wed, 8 Jan 2025 15:28:24 -0800 Subject: [PATCH] fix nil map dereference in discord commands, and add option type to slash command option Signed-off-by: Ava Affine --- internal/discord/commands.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/discord/commands.go b/internal/discord/commands.go index 7a13ed0..4499a85 100644 --- a/internal/discord/commands.go +++ b/internal/discord/commands.go @@ -12,7 +12,7 @@ import ( var ( // map of guildID to registeredCommands - registeredCommands map[string][]*discordgo.ApplicationCommand + registeredCommands = make(map[string][]*discordgo.ApplicationCommand) // all commands commandList = []*discordgo.ApplicationCommand{ @@ -28,6 +28,7 @@ var ( Description: "anonymously post a confession in configured channel", Options: []*discordgo.ApplicationCommandOption{ &discordgo.ApplicationCommandOption{ + Type: discordgo.ApplicationCommandOptionString, Name: "confession", Description: "A confession to be posted anonymously", Required: true, @@ -79,11 +80,11 @@ func registerCommands(s *discordgo.Session) { if err != nil { logging.Error( - "Failed to register commands for guild %s: %s", - guild.ID, err.Error(), + "Failed to register commands for guild", + guild.ID, ": ", err.Error(), ) } else { - logging.Info("Registered commands for guild %s", guild.ID) + logging.Info("Registered commands for guild ", guild.ID) registeredCommands[guild.ID] = cmds } } @@ -98,13 +99,13 @@ func deregisterCommands(s *discordgo.Session) { cmd.ID, ); err != nil { logging.Error( - "Failed to delete %s command (id: %s) from guild %s", - cmd.Name, cmd.ID, guild, + "Failed to delete", cmd.Name, "command (id:", cmd.ID, + ") from guild ", guild, ) } else { logging.Info( - "Deregistered command %s (id: %s) from guild %s", - cmd.Name, cmd.ID, guild, + "Deregistered command ", cmd.Name,"(id:", cmd.ID, + ") from guild ", guild, ) } }