From 492722af8b1962581802465581e3a041880b8808 Mon Sep 17 00:00:00 2001 From: James Nylen Date: Mon, 7 Jan 2019 15:39:53 -0500 Subject: Improve error reporting on failure to join Discord. Fixes #672 (#680) --- bridge/discord/discord.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'bridge/discord/discord.go') diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 16ce8c05..f27210b5 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -2,6 +2,7 @@ package bdiscord import ( "bytes" + "errors" "fmt" "strings" "sync" @@ -49,6 +50,7 @@ func New(cfg *bridge.Config) bridge.Bridger { func (b *Bdiscord) Connect() error { var err error var token string + var guildFound bool b.Log.Info("Connecting") if b.GetString("WebhookURL") == "" { b.Log.Info("Connecting using token") @@ -86,12 +88,24 @@ func (b *Bdiscord) Connect() error { if guild.Name == serverName || guild.ID == serverName { b.channels, err = b.c.GuildChannels(guild.ID) b.guildID = guild.ID + guildFound = true if err != nil { break } } } b.channelsMutex.Unlock() + if !guildFound { + msg := fmt.Sprintf("Server \"%s\" not found", b.GetString("Server")) + err = errors.New(msg) + b.Log.Error(msg) + b.Log.Info("Possible values:") + for _, guild := range guilds { + b.Log.Infof("Server=\"%s\" # Server name", guild.Name) + b.Log.Infof("Server=\"%s\" # Server ID", guild.ID) + } + } + if err != nil { return err } @@ -106,7 +120,7 @@ func (b *Bdiscord) Connect() error { defer b.membersMutex.Unlock() members, err := b.c.GuildMembers(b.guildID, "", 1000) if err != nil { - b.Log.Error("Error obtaining guild members", err) + b.Log.Error("Error obtaining server members: ", err) return err } for _, member := range members { -- cgit v1.2.3