discord-py-slash-commandでギルドコマンドにゴミが残ってしまった場合の対応
https://discord-py-slash-command.readthedocs.io/en/latest/faq.html#how-to-delete-slash-commands
discord-py-interactionsでは、sync_commandsをTrueにしていれば、自動的に削除してくれるのだけど、ゴミが残ってしまう場合がある
3種類方法があるけれど、自分がやったやつを紹介
下記のコマンドを使う
async discord_slash.utils.manage_commands.remove_all_commands_in(bot_id, bot_token, guild_id=None) link
bot_id – User ID of the bot.
bot_token – Token of the bot.
guild_id – ID of the guild to remove commands. Pass None to remove all global commands.
code:delete_guiild_command_all.py
from discord_slash.utils import manage_commands # for remove slash command
guilds = xxx, xxx, xxx # こんな感じでギルドIDのリストがあるとする
# DISCORD_TOKENは何らかの手法で保持しているトークン
async def on_ready(self):
LOG.info('We have logged in as {0.user}'.format(self))
for guild in guilds:
await manage_commands.remove_all_commands_in(self.user.id, DISCORD_TOKEN, guild)
LOG.info('remove all guild command for {0}.'.format(guild))
ポイント
discord_slashのサブパッケージである、discord_slash.utilsからmanage_commandsをインポートする
discord-py-slash-commandでギルドコマンドにゴミが残ってしまった場合の対応#60b94a0dfd049e000022218fにある通り、パラメータを設定する
asyncで使用するものなので、asyncメソッドのところで使い、awaitする