我想制作一个类似于Dyne的清除命令,在这里您可以输入一个用户,而它不清除用户的消息,只清除用户的消息(如果您输入一个用户)。我试过做一个单独的检查功能,但它不能清除任何东西。我没有错误,它只是不会清除
@commands.command()
@commands.has_permissions(manage_messages=True)
async def purge(self, ctx, user: discord.Member = None, num: int = 10000):
if user:
def check_func(user: discord.Member, message: discord.Message):
return not msg.pinned
return user.id
await ctx.message.delete()
await ctx.channel.purge(limit=num, check=check_func)
verycool = await ctx.send(f'{num} messages deleted.')
await verycool.delete()
else:
await ctx.message.delete()
await ctx.channel.purge(limit=num, check=lambda msg: not msg.pinned)
verycool = await ctx.send(f'{num} messages deleted.')
await verycool.delete()
我在服务器上具有“管理邮件”权限。有人知道如何使检查功能正常工作吗
我所做的改变应该可以解决你的问题,也可以解决其他一些问题
仅仅根据参数更改函数看起来更好,而且效率更高,否则您就有了重复的代码。此外,您在最后发送的消息会立即被有效删除},它将在给定的秒数后自动删除消息。还有一些我没有提到的其他语法问题,比如check函数只接受一个参数,但解析了两个参数,我也修复了这两个参数。从技术上讲,PEP8禁止在变量中存储lambda,但我认为这是可以原谅的
channel.send
有一个参数{编辑:您可以执行类似于检查
num == "*"
的操作,并删除所有消息相关问题 更多 >
编程相关推荐