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.
This commit is contained in:
Harvey Tindall 2021-05-23 01:09:03 +01:00
parent 44558b8109
commit 24fa841c0d
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
1 changed files with 4 additions and 0 deletions

View File

@ -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)