-
Hi, I'm just discovering golang and discordgo, and I have been facing a problem for several days: how can I catch a new auditlog, with a handler for example ? I want, in the end, to get ban logs and kick logs when they are created, to get the target user and the reason. Thank you, if you can help me... I even wonder if it's possible. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This has been implemented but unfortunatly hasn't been released in a stable version yet 6958472. You will need to the Here's some untested example code which should get the point across, your bot will also require the func onAuditLogEntryCreate(s *discordgo.Session, action *discordgo.GuildAuditLogEntryCreate) {
if *action.ActionType == discordgo.AuditLogActionMemberBanAdd{
log.Printf("User <@%s> banned <@%s> with reason '%s'", action.UserID, action.TargetID, action.Reason)
}
}
func main() {
dg, err := discordgo.New("Bot " + config.BotToken)
if err != nil {
log.Fatalln(err)
}
dg.Identify.Intents = discordgo.IntentGuildModeration // Or |=, to avoid resetting default intents
dg.AddHandler(onAuditLogEntryCreate)
} |
Beta Was this translation helpful? Give feedback.
-
Hi! Thank you for your answer. I forgot to mention it in here: I have indeed found this way to detect bans, but kicks are still complicated. I went down another path. |
Beta Was this translation helpful? Give feedback.
This has been implemented but unfortunatly hasn't been released in a stable version yet 6958472. You will need to the
master
version (go get -u github.com/bwmarrin/discordgo@master
) to get access to that right now. I'm doing that myself and have had no issues so don't be discouraged by that.Here's some untested example code which should get the point across, your bot will also require the
VIEW_AUDIT_LOG
permission to recieve them: