fix nil map dereference in discord commands, and add option type to slash command option

Signed-off-by: Ava Affine <ava@sunnypup.io>
This commit is contained in:
Ava Apples Affine 2025-01-08 15:28:24 -08:00
parent 359ff427e3
commit 55f9725af1

View file

@ -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,
)
}
}