// Create command handler (Command struct created below)
func CommandHandler(s *dis.Session, i *dis.InteractionCreate) {
s.InteractionRespond(i.Interaction, &dis.InteractionResponse{
Type: dis.InteractionResponseChannelMessageWithSource,
Data: &dis.InteractionResponseData{
Content: "Congrats! You've used the test command!",
},
})
}
func main() {
client := client_init() // Calls "dis.New("Bot" + TOKEN)" and retuns the result as "client".
set_intents(client) // Sets bot intents
fmt.Println(client.State.User.ID) // ERROR IS HERE! Why is the ID nil? The session didn't throw an error when it initialized.
var testCommand dis.ApplicationCommand = dis.ApplicationCommand{Name: "testCommand", Description: "This is a test command"} // Command struct
client.AddHandler(CommandHandler) // Registering handler
client.ApplicationCommandCreate(client.State.User.ID, "", &testCommand) // Registering command
err := client.Open() // Open the connection to Discord
if err != nil {
log.Fatal(err)
}
defer client.Close()
keep_alive() // Prevents the script from immediatly closing the connection and allows me to manually clost the connecction with "CTRL+C" in vs code
}
Error Message:
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x6ea499]
goroutine 1 [running]:
main.main()
/home/eulerian/Projects/[PROJECT_NAME]/main.go:24 +0x59
exit status 2
I'm not sure why the aforementioned ID is a nil (or invalid) pointer. Any other tips on structuring slash commands is also appreciated, as the example on github is literally over 500 lines long and difficult to read.