-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.go
54 lines (47 loc) · 1.23 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/bwmarrin/discordgo"
_ "github.com/joho/godotenv/autoload"
"os"
"os/signal"
)
func main() {
// Read environment variables.
token := os.Getenv("DISCORD_TOKEN")
if token == "" {
log.Fatal("No token specified; use env DISCORD_TOKEN")
return
}
// Create a Discord session.
s, err := discordgo.New("Bot " + token)
if err != nil {
log.WithError(err).Fatal("Couldn't create Discord session")
return
}
// Get app info, print invite link.
app, err := s.Application("@me")
if err != nil {
log.WithError(err).Fatal("Couldn't get application info")
return
}
perms := discordgo.PermissionSendMessages | discordgo.PermissionManageChannels | discordgo.PermissionManageRoles
fmt.Printf("https://discordapp.com/api/oauth2/authorize?client_id=%s&scope=bot&permissions=%d\n", app.ID, perms)
// Create the bot.
b := New(s, TheEntireBeeMovieScript)
// Set up a context that's canceled by any signal.
ctx, cancel := context.WithCancel(context.Background())
go func() {
quit := make(chan os.Signal)
signal.Notify(quit)
<-quit
signal.Reset()
cancel()
}()
// Run the bot.
if err := b.Run(ctx); err != nil {
log.WithError(err).Error("Error")
}
}