now actually stabilized command registering
This commit is contained in:
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -19,19 +20,28 @@ type Command struct {
|
|||||||
var commands []Command = []Command{tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command}
|
var commands []Command = []Command{tag_command, short_get_tag_command, dadjoke_command, ping_command, ask_command, sticky_command, cat_command}
|
||||||
|
|
||||||
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
fmt.Print("\nStarting up... (This may take a bit when Discord rate limits the bot)\n")
|
|
||||||
removeOldCommandFromAllGuilds(s)
|
removeOldCommandFromAllGuilds(s)
|
||||||
|
var existingCommandNames []string
|
||||||
for _, guild := range event.Guilds {
|
for _, guild := range event.Guilds {
|
||||||
|
existingCommands, err := s.ApplicationCommands(s.State.User.ID, guild.ID)
|
||||||
|
for _, existingCommand := range existingCommands {
|
||||||
|
existingCommandNames = append(existingCommandNames, existingCommand.Name)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("error fetching existing commands for guild %s: %v\n", guild.Name, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
for _, command := range commands {
|
for _, command := range commands {
|
||||||
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, guild.ID, &command.Definition)
|
if !slices.Contains(existingCommandNames, command.Definition.Name) || slices.Contains(os.Args, "--update") {
|
||||||
fmt.Printf("\nAdded command \"%s\"", cmd.Name)
|
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, guild.ID, &command.Definition)
|
||||||
if err != nil {
|
fmt.Printf("\nDeleted command \"%s\"", cmd.Name)
|
||||||
fmt.Println("error creating command,", err)
|
if err != nil {
|
||||||
continue
|
fmt.Println("error creating command,", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Print("Successfully started the Discord bot!")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func interactionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
Reference in New Issue
Block a user