私はコーディングに非常に慣れていないので、ここで「開発者の役割がない」などのカスタムエラーをどのように実装するのか疑問に思いました。
@bot.command()
@commands.has_any_role("Temp.", "Owner")
async def sh(ctx):
await ctx.message.add_reaction(':true:508022488093949973')
await ctx.send("<a:siren:507952050181636098> `Shutting down` <a:siren:507952050181636098>")
await bot.logout()
私はこのような単純なハンドラーを持っています
@bot.event
async def on_command_error(ctx, error):
await ctx.message.add_reaction(':false:508021839981707304')
await ctx.send("<a:siren:507952050181636098> `Invalid command` <a:siren:507952050181636098>")
しかし、それは常に無効なコマンドを出力するだけです
のクラスをチェックして、error
処理しているエラーの種類を判別できます。これをコマンド固有のエラーハンドラーと組み合わせると、不足しているものをユーザーに通知する応答を記述できます。
@sh.error
async def sh_error(ctx, error):
if isinstance(error, commands.CheckFailure):
await ctx.send("You do not have the correct roles Temp. or Owner")
@bot.event
async def on_command_error(ctx, error):
if not isinstance(error, commands.CheckFailure):
await ctx.message.add_reaction(':false:508021839981707304')
await ctx.send("<a:siren:507952050181636098> `Invalid command` <a:siren:507952050181636098>")
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加