forked from bwmarrin/discordgo
/
main.go
59 lines (50 loc) · 1.6 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
55
56
57
58
59
package main
import (
"flag"
"fmt"
"log"
"github.com/bwmarrin/discordgo"
)
// Flags
var (
GuildID = flag.String("guild", "", "Test guild ID")
StageChannelID = flag.String("stage", "", "Test stage channel ID")
BotToken = flag.String("token", "", "Bot token")
)
func init() { flag.Parse() }
// To be correctly used, the bot needs to be in a guild.
// All actions must be done on a stage channel event
func main() {
s, _ := discordgo.New("Bot " + *BotToken)
s.AddHandler(func(s *discordgo.Session, r *discordgo.Ready) {
fmt.Println("Bot is ready")
})
err := s.Open()
if err != nil {
log.Fatalf("Cannot open the session: %v", err)
}
defer s.Close()
// Create a new Stage instance on the previous channel
si, err := s.StageInstanceCreate(&discordgo.StageInstanceParams{
ChannelID: *StageChannelID,
Topic: "Amazing topic",
PrivacyLevel: discordgo.StageInstancePrivacyLevelGuildOnly,
SendStartNotification: true,
})
if err != nil {
log.Fatalf("Cannot create stage instance: %v", err)
}
log.Printf("Stage Instance %s has been successfully created", si.Topic)
// Edit the stage instance with a new Topic
si, err = s.StageInstanceEdit(*StageChannelID, &discordgo.StageInstanceParams{
Topic: "New amazing topic",
})
if err != nil {
log.Fatalf("Cannot edit stage instance: %v", err)
}
log.Printf("Stage Instance %s has been successfully edited", si.Topic)
if err = s.StageInstanceDelete(*StageChannelID); err != nil {
log.Fatalf("Cannot delete stage instance: %v", err)
}
log.Printf("Stage Instance %s has been successfully deleted", si.Topic)
}