got subcommands working
This commit is contained in:
@@ -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{
|
||||
@@ -50,5 +55,4 @@ func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.Intera
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
2
main.go
2
main.go
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user