1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-23 01:20:11 +00:00

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

View File

@ -76,6 +76,10 @@ func (d *DiscordDaemon) run() {
d.app.err.Printf("Discord: Failed to start daemon: %v", err) d.app.err.Printf("Discord: Failed to start daemon: %v", err)
return return
} }
// Sometimes bot.State isn't populated quick enough
for d.bot.State == nil {
continue
}
d.username = d.bot.State.User.Username d.username = d.bot.State.User.Username
// Choose the last guild (server), for now we don't really support multiple anyway // 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) guild, err := d.bot.Guild(d.bot.State.Guilds[len(d.bot.State.Guilds)-1].ID)