This repository was archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.go
More file actions
65 lines (52 loc) · 1.3 KB
/
Copy pathbot.go
File metadata and controls
65 lines (52 loc) · 1.3 KB
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
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/events"
"github.com/disgoorg/disgo/gateway"
"github.com/disgoorg/disgo/rest"
)
func main() {
log.Println("starting bot...")
// Create client
client, err := disgo.New(
os.Getenv("BOT_TOKEN"),
bot.WithGatewayConfigOpts(
gateway.WithIntents(gateway.IntentGuildMessages, gateway.IntentMessageContent),
),
bot.WithEventListenerFunc(onMessageCreate),
)
if err != nil {
log.Fatalf("failed to start: %v", err)
}
defer client.Close(context.Background())
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
// Connect to gateway
if err = client.OpenGateway(ctx); err != nil {
log.Fatalf("failed to connect to gateway: %v", err)
}
log.Println("connected!")
// Wait for interrupt
s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGINT, syscall.SIGTERM)
<-s
log.Println("disconnecting...")
}
func onMessageCreate(event *events.MessageCreate) {
// Ignore all bots
if event.Message.Author.Bot {
return
}
// Check if message is poll
if event.Message.Poll != nil {
// Delete message
event.Client().Rest().DeleteMessage(event.ChannelID, event.MessageID, rest.WithReason("Poll"))
}
}