Check if a user was mentioned, but ignore its own messages
parent
87360672f0
commit
80b71a47fb
24
buttsbot.go
24
buttsbot.go
|
@ -40,6 +40,7 @@ func main() {
|
||||||
|
|
||||||
//Handlers
|
//Handlers
|
||||||
Session.AddHandler(ready)
|
Session.AddHandler(ready)
|
||||||
|
Session.AddHandler(messageCreate)
|
||||||
|
|
||||||
//Open a connection to Discord
|
//Open a connection to Discord
|
||||||
err = Session.Open()
|
err = Session.Open()
|
||||||
|
@ -66,3 +67,26 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
|
||||||
s.UpdateStatus(0, "with butts!")
|
s.UpdateStatus(0, "with butts!")
|
||||||
s.ChannelMessageSend(bot_channel, "This isn't a butt...")
|
s.ChannelMessageSend(bot_channel, "This isn't a butt...")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
//Ignore messages by itself
|
||||||
|
if m.Author.ID == s.State.User.ID {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
//Check if the bot was mentioned
|
||||||
|
if isUserMentioned(m, s.State.User) == true {
|
||||||
|
s.ChannelMessageSend(m.ChannelID, "butt")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Easy way to check if a user was mentioned in a message
|
||||||
|
func isUserMentioned(m *discordgo.MessageCreate, u *discordgo.User) bool {
|
||||||
|
//mentioned := false
|
||||||
|
for _, user := range m.Mentions {
|
||||||
|
if user.ID == u.ID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue