Skip to content

Commit

Permalink
fix: resolve crash if the bot leaves a guild it doesn't have in its d…
Browse files Browse the repository at this point in the history
…atabase
  • Loading branch information
sylvrs committed Nov 26, 2024
1 parent 99767cb commit faaeef2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,15 @@ func (mng *Manager) onGuildJoin(event *discordgo.GuildCreate) {
}

func (mng *Manager) onGuildLeave(event *discordgo.GuildDelete) {
mng.Logger().Info("Left guild", "guild", event.ID)
var guildConfig GuildConfiguration
if mng.Connection().Where("guild_id = ?", event.Guild.ID).Find(&guildConfig).RowsAffected == 0 {
mng.Logger().Error("Received guild deletion event but no associated guild found in database", "guild", event.Guild)
return
}
if err := mng.deleteGuild(event.Guild); err != nil {
mng.Logger().Error("Failed to delete guild", "guild", event.ID, "error", err)
}
mng.Logger().Info("Left guild", "guild", event.ID)
}

func (mng *Manager) onReceiveCommand(event *discordgo.InteractionCreate) {
Expand Down

0 comments on commit faaeef2

Please sign in to comment.