From 24fa841c0d8464e88758c982355d0e03d4ffa36c Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Sun, 23 May 2021 01:09:03 +0100 Subject: [PATCH] Discord: Wait for non-nil pointer to bot data While testing others things, I had quite a few nil pointer dereference errors from accessing bot data right after initializing. A for loop now waits until the first of the pointers is non-nil, which should hopefully avoid crashes. --- discord.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/discord.go b/discord.go index 3d92ead..9129ffb 100644 --- a/discord.go +++ b/discord.go @@ -76,6 +76,10 @@ func (d *DiscordDaemon) run() { d.app.err.Printf("Discord: Failed to start daemon: %v", err) return } + // Sometimes bot.State isn't populated quick enough + for d.bot.State == nil { + continue + } d.username = d.bot.State.User.Username // Choose the last guild (server), for now we don't really support multiple anyway guild, err := d.bot.Guild(d.bot.State.Guilds[len(d.bot.State.Guilds)-1].ID)