You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Will Navidson edited this page Jun 30, 2017
·
5 revisions
First, lets create our HelloHandler, which will listen for the string hello in every channel that our bot has access to.
package main
import (
"fmt""github.com/bwmarrin/discordgo"
)
typeHelloHandlerstruct {
conf*Config
}
func (h*HelloHandler) Read(s*discordgo.Session, m*discordgo.MessageCreate) {
// Ignore all messages created by the bot itselfifm.Author.ID==s.State.User.ID {
return
}
// Ignore botsifm.Author.Bot {
return
}
// Set our command prefix to the default one within our config filecp:=h.conf.DUBotConfig.CP// If the message read is "hello" reply in the same channel with "Hi!"ifm.Content==cp+"hello" {
s.ChannelMessageSend( m.ChannelID, "Hi!")
}
}
That's it!
As you can see, the process of adding more strings to listen for is fairly easy, just remember to take the command prefix into account.
You can save this file as hello_handler.go, I like the underscore in the filename because it's easy for me to distinguish handler files in a directory listing.