got subcommands working

This commit is contained in:
2024-02-15 14:09:32 +01:00
parent 4eb48cbfe1
commit 191b110846
2 changed files with 39 additions and 35 deletions

View File

@@ -8,8 +8,13 @@ import (
var tag_command Command = Command{
Definition: discordgo.ApplicationCommand{
Name: "tag",
Description: "A command to show and edit saved presaved messages.",
Options: []*discordgo.ApplicationCommandOption{
{
Name: "get",
Description: "A command to get messages saved to the bot.",
Type: discordgo.ApplicationCommandOptionSubCommand,
Options: []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionString,
@@ -20,9 +25,12 @@ var tag_command Command = Command{
},
},
},
}
},
}}
func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.ApplicationCommandData().Options[0].Name {
case "get":
if i.Type == discordgo.InteractionApplicationCommandAutocomplete {
commandUseCount++
choices := generateDynamicChoices(commandUseCount)
@@ -34,11 +42,8 @@ func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.Intera
})
}
if i.Type == discordgo.InteractionApplicationCommand {
if len(i.ApplicationCommandData().Options) > 0 {
// Loop through the options and handle them
for _, option := range i.ApplicationCommandData().Options {
switch option.Name {
case "tag":
option := i.ApplicationCommandData().Options[0].Options[0]
if option.Name == "tag" {
value := option.Value.(string)
response := fmt.Sprintf("You provided the tag: %s", value)
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
@@ -51,4 +56,3 @@ func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.Intera
}
}
}
}

View File

@@ -73,7 +73,7 @@ func generateDynamicChoices(count int) []*discordgo.ApplicationCommandOptionChoi
var commandUseCount int
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
if i.ApplicationCommandData().Name == "get" {
if i.ApplicationCommandData().Name == "tag" {
tag_command.Interaction(s, i)
}
}