got subcommands working
This commit is contained in:
@@ -8,8 +8,13 @@ import (
|
|||||||
|
|
||||||
var tag_command Command = Command{
|
var tag_command Command = Command{
|
||||||
Definition: discordgo.ApplicationCommand{
|
Definition: discordgo.ApplicationCommand{
|
||||||
|
Name: "tag",
|
||||||
|
Description: "A command to show and edit saved presaved messages.",
|
||||||
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
|
{
|
||||||
Name: "get",
|
Name: "get",
|
||||||
Description: "A command to get messages saved to the bot.",
|
Description: "A command to get messages saved to the bot.",
|
||||||
|
Type: discordgo.ApplicationCommandOptionSubCommand,
|
||||||
Options: []*discordgo.ApplicationCommandOption{
|
Options: []*discordgo.ApplicationCommandOption{
|
||||||
{
|
{
|
||||||
Type: discordgo.ApplicationCommandOptionString,
|
Type: discordgo.ApplicationCommandOptionString,
|
||||||
@@ -20,9 +25,12 @@ var tag_command Command = Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
},
|
||||||
|
}}
|
||||||
|
|
||||||
func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func (tag_command Command) Interaction(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
switch i.ApplicationCommandData().Options[0].Name {
|
||||||
|
case "get":
|
||||||
if i.Type == discordgo.InteractionApplicationCommandAutocomplete {
|
if i.Type == discordgo.InteractionApplicationCommandAutocomplete {
|
||||||
commandUseCount++
|
commandUseCount++
|
||||||
choices := generateDynamicChoices(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 i.Type == discordgo.InteractionApplicationCommand {
|
||||||
if len(i.ApplicationCommandData().Options) > 0 {
|
option := i.ApplicationCommandData().Options[0].Options[0]
|
||||||
// Loop through the options and handle them
|
if option.Name == "tag" {
|
||||||
for _, option := range i.ApplicationCommandData().Options {
|
|
||||||
switch option.Name {
|
|
||||||
case "tag":
|
|
||||||
value := option.Value.(string)
|
value := option.Value.(string)
|
||||||
response := fmt.Sprintf("You provided the tag: %s", value)
|
response := fmt.Sprintf("You provided the tag: %s", value)
|
||||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
@@ -51,4 +56,3 @@ 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
|
var commandUseCount int
|
||||||
|
|
||||||
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
if i.ApplicationCommandData().Name == "get" {
|
if i.ApplicationCommandData().Name == "tag" {
|
||||||
tag_command.Interaction(s, i)
|
tag_command.Interaction(s, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user