/
main.go
97 lines (77 loc) · 2.33 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/TheBoringDude/minidis"
"github.com/bwmarrin/discordgo"
)
func main() {
bot := minidis.New(os.Getenv("TOKEN"))
// set intents
bot.SetIntents(discordgo.IntentsGuilds | discordgo.IntentsGuildMessages)
//
bot.SyncToGuilds(os.Getenv("GUILD"))
bot.OnReady(func(s *discordgo.Session, i *discordgo.Ready) {
log.Println("Bot is ready!")
})
// simple command
bot.AddCommand(&minidis.SlashCommandProps{
Name: "ping",
Description: "Simple ping command.",
DefaultMemberPermissions: 1 << 31,
Options: []*discordgo.ApplicationCommandOption{},
Execute: func(c *minidis.SlashContext) error {
return c.ReplyString(fmt.Sprintf("Hello **%s**, pong? Guild: %s", c.Author.Username, c.GuildId))
},
})
// deferred replies
bot.AddCommand(&minidis.SlashCommandProps{
Name: "defer",
Description: "Deferred reply.",
DefaultMemberPermissions: 1 << 31,
Execute: func(c *minidis.SlashContext) error {
c.DeferReply(true)
time.Sleep(time.Second * 5)
return c.Edit("This is a deffered reply edit message!")
},
})
// responses
bot.AddCommand(&minidis.SlashCommandProps{
Name: "responses",
Description: "Responses management.",
Options: []*discordgo.ApplicationCommandOption{},
Execute: func(s *minidis.SlashContext) error {
if err := s.ReplyString("Hello! this message will be modified after 5 seconds..."); err != nil {
_, err = s.Followup("A problem has occured")
return err
}
time.Sleep(time.Second * 5)
s.Edit("new message here!")
time.Sleep(time.Second * 5)
_, err := s.Followup("another message in here!")
return err
},
})
bot.AddCommand(&minidis.SlashCommandProps{
Name: "admin-only",
Description: "Admin only command",
DefaultMemberPermissions: 0, // 0 = admin only command
Execute: func(s *minidis.SlashContext) error {
return s.ReplyString("You should only see this reply if you are an admin!")
},
})
bot.OnBeforeStart(func(s *discordgo.Session) {
// try to remove old commands first
if err := bot.ClearCommands(); err != nil {
log.Fatal(err)
}
})
bot.OnClose(func(s *discordgo.Session) {
log.Println("Closing...")
})
if err := bot.Run(); err != nil {
log.Fatalln(err)
}
}