Python discord.py-如何清除提到的用户的消息?

Python discord.py-如何清除提到的用户的消息?,python,discord.py,Python,Discord.py,我发现了这一点,但由于某种原因,当我提到一个用户时,它没有发现。当我执行命令时,它不会在终端上显示任何错误。问题中的代码如下所示: @commands.command() @commands.has_权限(manage_messages=True) 异步def清除(self,ctx,num:int,user:discord.Member=None): 如果用户: 检查_func=lambda msg:msg.author==user而不是msg 其他: 检查\u func=lambda消息:非消

我发现了这一点,但由于某种原因,当我提到一个用户时,它没有发现。当我执行命令时,它不会在终端上显示任何错误。问题中的代码如下所示:

@commands.command()
@commands.has_权限(manage_messages=True)
异步def清除(self,ctx,num:int,user:discord.Member=None):
如果用户:
检查_func=lambda msg:msg.author==user而不是msg
其他:
检查\u func=lambda消息:非消息
等待ctx.message.delete()
等待ctx.channel.purge(限制=num,检查=check\u func)
等待ctx.send(f'{num}消息已删除',delete_after=5)
它只适用于大量消息,如
q!清除5,但不要使用
q!清除5@SomeUser#1234

这可以使用

@bot.command()
异步def清除(ctx,限制=50,成员:discord.member=None):
等待ctx.message.delete()
味精=[]
尝试:
极限=int(极限)
除:
return wait ctx.send(“请输入一个整数作为限制”)
如果不是成员:
等待ctx.channel.purge(限制=限制)
return wait ctx.send(f“清除{limit}消息”,delete_after=3)
ctx.channel.history()中m的异步:
如果len(msg)=限制:
打破
如果m.author==成员:
附加消息(m)
等待ctx.channel.delete_消息(msg)
等待ctx.send(f“清除{member.ntify}的{limit}消息”,删除=3后的_)