From 4cbb5f47ba93ee7d9f31145db0d4e798fd61088c Mon Sep 17 00:00:00 2001 From: Ashish Jhanwar Date: Sun, 16 Jun 2024 11:07:45 +0530 Subject: [PATCH] fix for panic on nil guildMessages list --- lib/dstate/inmemorytracker/tracker.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/dstate/inmemorytracker/tracker.go b/lib/dstate/inmemorytracker/tracker.go index 357927e623..204e06e3a4 100644 --- a/lib/dstate/inmemorytracker/tracker.go +++ b/lib/dstate/inmemorytracker/tracker.go @@ -645,7 +645,14 @@ func (shard *ShardTracker) handleMessageCreate(m *discordgo.MessageCreate) { // Insert *list.Element.Value into guildMessages so that we only need to perform // state changes for the channel lists - shard.guildMessages[m.GuildID].PushBack(&elem.Value) + // Ensure that the guildMessages list is created as guildCreate events could be missed + if gc, ok := shard.guildMessages[m.GuildID]; ok { + gc.PushBack(&elem.Value) + } else { + gc := list.New() + gc.PushBack(&elem.Value) + shard.guildMessages[m.GuildID] = gc + } } func (shard *ShardTracker) handleMessageUpdate(m *discordgo.MessageUpdate) {