-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrm_commands.go
73 lines (64 loc) · 1.52 KB
/
rm_commands.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
package main
import (
"context"
"log/slog"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/snowflake/v2"
)
func rmCommands(token string, global bool, guildID uint64) {
client, err := disgo.New(token)
if err != nil {
slog.Error("Failed to create client")
panic(err)
}
defer client.Close(context.Background())
if global {
rmGlobal(client)
}
if guildID != 0 {
rmGuild(client, guildID)
}
}
func rmGlobal(client bot.Client) {
cmds, err := client.Rest().GetGlobalCommands(client.ApplicationID(), false)
if err != nil {
slog.Error("Failed to get global commands")
panic(err)
}
for _, cmd := range cmds {
slog.Info("Deleting global command", "name", cmd.Name)
err = client.Rest().DeleteGlobalCommand(
client.ApplicationID(),
cmd.ID(),
)
if err != nil {
slog.Error("Failed to delete global command",
"command_id", cmd.ID(),
"name", cmd.Name)
panic(err)
}
}
}
func rmGuild(client bot.Client, guildID uint64) {
cmds, err := client.Rest().GetGuildCommands(client.ApplicationID(), snowflake.ID(guildID), false)
if err != nil {
slog.Error("Failed to get guild commands")
panic(err)
}
for _, cmd := range cmds {
slog.Info("Deleting guild command", "name", cmd.Name, "guild_id", guildID)
err = client.Rest().DeleteGuildCommand(
client.ApplicationID(),
snowflake.ID(guildID),
cmd.ID(),
)
if err != nil {
slog.Error("Failed to delete guild command",
"guild_id", guildID,
"command_id", cmd.ID(),
"name", cmd.Name)
panic(err)
}
}
}