adds leave command and bot to delete all commands for a bot
This commit is contained in:
parent
44c67ffd42
commit
fc2a748cd4
2 changed files with 74 additions and 75 deletions
60
cmd/delcombot/main.go
Normal file
60
cmd/delcombot/main.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/disgoorg/disgo"
|
||||
"github.com/disgoorg/disgo/bot"
|
||||
"github.com/disgoorg/disgo/cache"
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/gateway"
|
||||
"github.com/disgoorg/log"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
token = os.Getenv("disgo_token")
|
||||
noCommands []discord.ApplicationCommandCreate
|
||||
)
|
||||
|
||||
// this bot should in theory delete all registered commands for a certain bot
|
||||
func main() {
|
||||
log.SetLevel(log.LevelDebug)
|
||||
log.Info("starting delcombot...")
|
||||
log.Info("disgo version: ", disgo.Version)
|
||||
|
||||
// permissions:
|
||||
// intent:
|
||||
client, err := disgo.New(token,
|
||||
bot.WithGatewayConfigOpts(
|
||||
gateway.WithIntents(gateway.IntentsNone),
|
||||
),
|
||||
bot.WithCacheConfigOpts(
|
||||
cache.WithCaches(
|
||||
cache.FlagsNone,
|
||||
),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal("error while building disgo instance: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer client.Close(context.TODO())
|
||||
|
||||
client.Caches().GuildsForEach(func(guild discord.Guild) {
|
||||
if _, err = client.Rest().SetGuildCommands(client.ApplicationID(), guild.ID, noCommands); err != nil {
|
||||
log.Info(fmt.Sprintf("error deleting guild commands from %v: ", guild.Name), err)
|
||||
}
|
||||
})
|
||||
|
||||
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), noCommands); err != nil {
|
||||
log.Info("error deleting global commands", err)
|
||||
}
|
||||
|
||||
if err = client.OpenGateway(context.TODO()); err != nil {
|
||||
log.Fatal("error while connecting to gateway: ", err)
|
||||
}
|
||||
|
||||
log.Infof("delcombot removed all guild and global commands")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue