Search code examples
godiscorddiscordgo

Deleting a discord message from discordgo


I am trying to delete a discord message using discordgo. Currently I have the ping pong example, however instead of writing a message I want to delete the message.

I have currently got this far:

func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {

    if m.Author.ID == s.State.User.ID || m.Author.Bot {
        return
    }

    if m.Content == "ping" {
        s.ChannelMessageDelete(m.ChannelID, m.ID)
    }
}

But the implementation does not delete the message even though other code in the block will run. I am a bit of a newb to go and I don't know if there is some future error .. or something like the bot does not have the correct discord permissions?


Solution

  • The reason it was not posting was because the bot did not have the Manage Messages permission. This can be done by checking the Manage Messages checkbox when generating the invite link on the OAuth tab.