2
0
mirror of https://github.com/42wim/matterbridge synced 2024-11-17 03:26:07 +00:00

Improve error reporting on failure to join Discord. Fixes #672 (#680)

This commit is contained in:
James Nylen 2019-01-07 15:39:53 -05:00 committed by Wim
parent 56749dfb20
commit 492722af8b

View File

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