package bot import ( "fmt" "log" "os" "os/signal" commands "ion606_bot/Bot/Commands" "github.com/bwmarrin/discordgo" ) var BotToken string // commandHandlers maps command names to their interaction handler functions. var commandHandlers = map[string]func(*discordgo.Session, *discordgo.InteractionCreate){ "meow": commands.HandleMeow, "purr": commands.HandlePurr, "boop": commands.HandleBoop, "hug": commands.HandleHug, "cuddle": commands.HandleCuddle, "snuggle": commands.HandleSnuggle, "catfact": commands.HandleCatfact, "animalgif": commands.HandleAnimalGif, "action": commands.HandleAction, } // Run starts the Discord bot session and listens for both message and slash command events. func Run() { // create a session using the provided bot token. discord, err := discordgo.New("Bot " + BotToken) if err != nil { log.Fatal("Error creating Discord session: ", err) } // add event handlers for messages and interactions. discord.AddHandler(newMessage) discord.AddHandler(handleInteractionCreate) err = discord.Open() if err != nil { log.Fatal("Error opening Discord session: ", err) } RegisterCommands(discord, "") fmt.Println("Bot running....") c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt) <-c err = discord.Close() if err != nil { log.Println("Error closing Discord session: ", err) } } func newMessage(s *discordgo.Session, m *discordgo.MessageCreate) { // prevent the bot from responding to its own messages. if m.Author.ID == s.State.User.ID { return } } func handleInteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) { name := i.ApplicationCommandData().Name if handler, found := commandHandlers[name]; found { handler(s, i) } else { log.Printf("No handler found for command: %v", name) } }