From 9fffe55084a724eb7d6350a8c2cb4540d3350cb9 Mon Sep 17 00:00:00 2001 From: Evan Zelkowitz Date: Thu, 5 Nov 2020 08:12:04 -0700 Subject: [PATCH] Add a warning if the guilds array is empty, this indicates the bot has not been invited to any servers and so hands out the invite link (#42) --- main.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 1e99142..d4d903e 100644 --- a/main.go +++ b/main.go @@ -169,8 +169,15 @@ func ready(s *discordgo.Session, event *discordgo.Ready) { s.UpdateStatus(0, "") //SendEmbed(s, config.BroadcastChannel, "", "I iz here", "Keybot has arrived. You may now use me like the dumpster I am") if config.KeyRole != "" { - guildID = event.Guilds[0].ID - refreshRoles(s) + if len(event.Guilds) > 0 { + guildID = event.Guilds[0].ID + refreshRoles(s) + } else { + fmt.Println("Error: No servers returned from discord. Make sure to invite your bot to your server first") + fmt.Println("Error: You can do that with https://discord.com/oauth2/authorize?client_id=123451234512345&scope=bot") + fmt.Println("Error: Replace the number with your bot's clientid value from your developer portal") + os.Exit(4) + } } initialized = true