【发布时间】:2021-03-12 22:50:52
【问题描述】:
我目前正在尝试处理我的 discord bot clear 命令中的错误。我的代码如下:
@commands.command(name='clear', aliases=['clean', 'cleanup'])
@commands.guild_only()
@commands.has_permissions(manage_messages=True)
async def clear(self, ctx, message, limit: int = 10) -> None:
await ctx.message.add_reaction("<:tars_certo:783051315764133910>")
time.sleep(2)
messages = await ctx.channel.purge(bulk=True, limit=limit)
embed=discord.Embed(title=f"`{len(messages)}` mensagens deletadas com sucesso", color=COR_PRINCIPAL)
embed.set_author(name="Plugin de comandos do TARS",icon_url=ICONE)
await ctx.send(embed=embed, delete_after=5)
@clear.error
async def clear_error(ctx, error):
if isinstance(error, MissingPermissions):
embed=discord.Embed(title="<:tars_x:783051246776877057> Erro: Você não tem permissão para usar este comando", color=COR_PRINCIPAL)
embed.set_author(name="TARS help",icon_url=ICONE)
await ctx.send(embed=embed)
但是,由于某种原因,我收到了当前错误:
Command raised an exception: TypeError: clear_error() takes 2 positional arguments but 3 were given
这是完整的错误:
Ignoring exception in on_message
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 851, in invoke
await self.prepare(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 778, in prepare
if not await self.can_run(ctx):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1076, in can_run
return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/utils.py", line 338, in async_all
for elem in gen:
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1076, in <genexpr>
return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 1769, in predicate
raise MissingPermissions(missing)
discord.ext.commands.errors.MissingPermissions: You are missing Manage Messages permission(s) to run this command.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 71, in wrapped
ret = await coro(*args, **kwargs)
TypeError: clear_error() takes 2 positional arguments but 3 were given
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 943, in on_message
await self.process_commands(message)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 940, in process_commands
await self.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 907, in invoke
await ctx.command.dispatch_error(ctx, exc)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 422, in dispatch_error
await injected(cog, ctx, error)
File "/opt/virtualenvs/python3/lib/python3.8/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: clear_error() takes 2 positional arguments but 3 were given
我做错了什么?提前谢谢你。
【问题讨论】:
标签: python python-3.x discord bots discord.py