discord.py v2.0のCogでチェック失敗をキャッチ
Danny — 2022/08/28
There is no on_error for cogs
code:cog.py
class TestCog(commands.Cog):
@app_commands.command(
name='check-test'
description='テスト')
@app_commands.describe(
option='オプション')
@app_commands.guild_only() # ギルドだけ(DM禁止)
@app_commands.checks.has_permissions(administrator=True) # 管理者権限保有者のみ
await interaction.followup.send('テスト!!', ephemeral = True)
# 以下の部分でキャッチしてます
async def cog_app_command_error(self, interaction, error):
if isinstance(error, app_commands.CheckFailure):
await interaction.response.send_message('チェック失敗!')
async def setup(bot):
LOG.info('TestBotを読み込む!')
await bot.add_cog(TestCog(bot)) # TestCogにBotを渡してインスタンス化し、Botにコグとして登録する。