Check if a user was mentioned, but ignore its own messages

pull/2/head
pocketjawa 2019-04-27 12:41:17 -04:00
parent 87360672f0
commit 80b71a47fb
1 changed files with 24 additions and 0 deletions

View File

@ -40,6 +40,7 @@ func main() {
//Handlers
Session.AddHandler(ready)
Session.AddHandler(messageCreate)
//Open a connection to Discord
err = Session.Open()
@ -66,3 +67,26 @@ func ready(s *discordgo.Session, event *discordgo.Ready) {
s.UpdateStatus(0, "with butts!")
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
}