Skip to content

Commit 73f9f1c

Browse files
committed
Workaround for disgord.CreateBotURL() bug (Fixes #5)
1 parent 2b04792 commit 73f9f1c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

bot.go

+20-14
Original file line numberDiff line numberDiff line change
@@ -143,28 +143,26 @@ func runBot(token string) error {
143143
return err
144144
}
145145

146-
filter, err := std.NewMsgFilter(bot)
147-
if err != nil {
148-
return err
149-
}
150-
bot.On(event.MessageCreate, filter.HasBotMentionPrefix, onMessageCreate)
146+
bot.AddPermission(disgord.PermissionManageChannels)
147+
151148
bot.On(event.Ready, onReady)
152149

153-
bot.AddPermission(disgord.PermissionManageChannels)
154-
url, err := bot.CreateBotURL()
150+
filter, err := std.NewMsgFilter(bot)
155151
if err != nil {
156152
return err
157153
}
154+
bot.On(event.MessageCreate, filter.HasBotMentionPrefix, onMessageCreate)
158155

159-
logr.Info("Starting bot connection")
156+
logr.Info("Connecting")
160157
start := time.Now()
161158
if err = bot.Connect(); err != nil {
162159
return err
163160
}
164161
logr.Info("Connection took ", time.Since(start))
165-
logr.Infof("Link to add the bot to your server:\n%s", url)
166162

163+
logr.Info("Press Ctrl+C to exit")
167164
bot.DisconnectOnInterrupt()
165+
168166
return nil
169167
}
170168

@@ -174,13 +172,21 @@ func onReady(session disgord.Session, evt *disgord.Ready) {
174172
})
175173
if err != nil {
176174
logr.Error(err)
177-
return
175+
} else {
176+
guildString := "Connected guilds:\n"
177+
for i, guild := range guilds {
178+
guildString += fmt.Sprintf("%d: %s (%s)\n", i+1, guild.Name, guild.ID)
179+
}
180+
logr.Info(guildString)
178181
}
179-
guildString := "Connected guilds:\n"
180-
for i, guild := range guilds {
181-
guildString += fmt.Sprintf("%d: %s (%s)\n", i+1, guild.Name, guild.ID)
182+
183+
user, err := session.GetCurrentUser()
184+
if err != nil {
185+
logr.Error(err)
186+
} else {
187+
url := fmt.Sprintf("https://discordapp.com/oauth2/authorize?scope=bot&client_id=%s&permissions=%d", user.ID, session.GetPermissions())
188+
logr.Infof("Link to add bot to your guild:\n%s", url)
182189
}
183-
logr.Info(guildString)
184190
}
185191

186192
func onMessageCreate(session disgord.Session, evt *disgord.MessageCreate) {

0 commit comments

Comments
 (0)