#I want create a discord slash command . How do I do that?

9 messages · Page 1 of 1 (latest)

austere pelican
#

This my code

var GuildID = flag.String("guild", "", "Test guild ID. If not passed - bot registers commands globally")

func init() { flag.Parse() }

func DiscordHandler() {

    dg, err := discordgo.New("Bot " + DISCORD)

    if err != nil {
        fmt.Println("Error creating Discord session,", err)
        return
    }

    dg.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
        if i.Type == discordgo.InteractionApplicationCommand {
            switch i.ApplicationCommandData().Name {
            case "hello":
                s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
                    Type: discordgo.InteractionResponseChannelMessageWithSource,
                    Data: &discordgo.InteractionResponseData{
                        Content: "HELLO",
                    },
                })
            }
        }
    })

    dg.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
        SendMessages(s, m)
    })

    dg.Identify.Intents = discordgo.IntentsAllWithoutPrivileged

    err = dg.Open()

    if err != nil {
        fmt.Println("Error opening connection,", err)
        return
    }

    defer dg.Close()

    fmt.Println("AetherAI is online")

    sc := make(chan os.Signal, 1)
    signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
    <-sc

}

acoustic summit
#

Where is the part where you register the command?

austere pelican
acoustic summit
austere pelican
#

but its long and didnt work

#

i only want to add four commands

ornate girder
#

that linked line is whats registering the commands to discord itself - without it you won't get the popup in the client when you start typing /

#

line 40 in the same file is where the commands are defined