[英]Delete messages from specifc user using Discord py
我想创建一个 clear 命令,如果 example.clear @user#0000 100 它将清除 @user#0000 发送的最后 100 条消息。 这是我的代码:
@commands.command()
@commands.has_permissions(manage_messages=True)
async def clear(self, ctx, amount=1):
await ctx.channel.purge(limit=amount + 1)
@clear.error
async def clear_error(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
await ctx.send('Sorry, you are missing the ``MANAGE_MESSAGES`` permission to use this command.')
我提供的此代码仅删除取决于频道中将删除多少条消息。 我想制作一个代码,机器人将删除来自特定用户的消息。 如果这是可能的,请告诉我。 我将使用该代码作为将来的参考。 非常感激。
您可以使用check
kwarg 清除来自特定用户的消息:
@commands.command()
@commands.has_permissions(manage_messages=True)
async def clear(self, ctx, member: discord.Member, amount: int = 1):
await ctx.channel.purge(limit=amount, check=lambda m: m.author == member)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.