discordBots/cmd/delcombot/main.go
2023-11-05 16:03:52 +00:00

60 lines
1.6 KiB
Go

package main
import (
"context"
"github.com/disgoorg/disgo"
"github.com/disgoorg/disgo/bot"
"github.com/disgoorg/disgo/cache"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/gateway"
"log/slog"
"os"
)
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil))
var (
token = os.Getenv("disgo_token")
noCommands []discord.ApplicationCommandCreate
)
// this bot should in theory delete all registered commands for a certain bot
func main() {
logger.Info("starting delcombot...", slog.String("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 {
logger.Error("error while building disgo instance", slog.Any("error", 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 {
logger.Info("error deleting guild commands", slog.String("guild name", guild.Name), slog.Any("error", err))
}
})
if _, err = client.Rest().SetGlobalCommands(client.ApplicationID(), noCommands); err != nil {
logger.Info("error deleting global commands", slog.Any("error", err))
}
if err = client.OpenGateway(context.TODO()); err != nil {
logger.Error("error while connecting to gateway", slog.Any("error", err))
return
}
logger.Info("delcombot removed all guild and global commands")
}