删除discord-rewrite.py中的用户消息

时间:2018-06-27 18:30:37

标签: python discord discord.py discord.py-rewrite

该命令应该执行的操作是删除指定数量的消息,但是却出现错误:

select (date_trunc('month', current_date) + interval '1 month' -
        (case extract(dow from date_trunc('month', current_date) + interval '1 month')
              when 0 then 2
              when 1 then 3
              else 1
         end) * interval '1 day'
       ) as last_weekday_in_month

我尝试过的代码:

Ignoring exception in command clear:
Traceback (most recent call last):
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "c:/Users/dimit/Desktop/Discord Bot Shit/BasicBot.py", line 54, in clear
    await channel.purge(messages)
TypeError: purge() takes 1 positional argument but 2 were given

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 498, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "C:\Users\dimit\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: purge() takes 1 positional argument but 2 were given

1 个答案:

答案 0 :(得分:3)

purge实际上没有收到要删除的消息列表(尽管文档的措辞与实际情况相同)。取而代之的是,它使用许多关键字参数来确定是否应删除消息。试试

@bot.command()
async def clear(ctx, amount: int):
    await ctx.channel.purge(limit=amount)