python - 获取 discord.ext.commands.errors.CommandInvokeError:
问题描述
我的 Python 代码:
@bot.command(aliases = ["crole","cr"])
@commands.has_permissions(manage_roles = True)
async def createrole(ctx, *, name):
guild = ctx.guild
await guild. create_role(name=name)
await ctx.send(f'Role `{name}` has been created')
#create role error
@createrole.error
async def createrole_error(self, ctx, error):
if isinstance(error, MissingRequiredArgument):
createrole= discord.Embed(
title = f'Command: {prefix}createrole',
colour = discord.Colour.from_rgb(0,0,0)
)
createrole.add_field(name= 'Description:', value= 'Create a Role',inline=False)
createrole.add_field(name= 'Usage:', value = f'`{prefix}createrole [rolename] [color]`',inline=False)
createrole.add_field(name='Example:', value= f'`{prefix}createrole @parth normal`',inline=False)
await ctx.send(f"{createrole}")
elif isinstance(error,commands.BotMissingPermissions):
permission_error = discord.Embed(description = f"❌ I Am Missing **MANAGE ROLES** Permisson"
,colour = discord.Colour.from_rgb(0,0,0))
await ctx.send(embed = permission_error)
通过发送不完整的命令>createrole来检查我的 MissingRequiredArgument 消息是否已发送但出现此错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 847, in invoke
await self.prepare(ctx)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 784, in prepare
await self._parse_arguments(ctx)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 699, in _parse_arguments
kwargs[name] = await self.transform(ctx, param)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 535, in transform
raise MissingRequiredArgument(param)
discord.ext.commands.errors.MissingRequiredArgument: name is a required argument that is missing.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped
ret = await coro(*args, **kwargs)
TypeError: createrole_error() missing 1 required positional argument: 'error'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Mridul Folder\python\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\bot.py", line 943, in on_message
await self.process_commands(message)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\bot.py", line 940, in process_commands
await self.invoke(ctx)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\bot.py", line 907, in invoke
await ctx.command.dispatch_error(ctx, exc)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 417, in dispatch_error
await injected(ctx, error)
File "D:\Mridul Folder\python\lib\site-packages\discord\ext\commands\core.py", line 77, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: createrole_error() missing 1 required positional argument: 'error'
解决方案
推荐阅读
- javascript - NodeJS Express 反向代理 TLS_CERT_ALTNAME_INVALID 错误
- python - 如何使用 Python 在 Mtom/xop 请求中发送 Content-id
- excel - 无法使用应用程序调用者获取 ActiveX 复选框属性
- python - 如何更改字符串编码?
- wordpress - WooCommerce:在管理端订单列表页面自定义列中显示 SKU 编号
- python - 在 pyspark 中执行 groupBy 时,“TypeError:strptime() 参数 1 必须是 str,而不是 None”
- performance - 进行任何交易时 CPU 使用率将达到 100%
- xamarin - 在 UI 线程上执行 MVVMCross 值转换器逻辑
- autosar - 软件集群中的诊断地址有什么用?
- ssl - 无法使用 Squid 4.8 打开一些 HTTPS