【问题标题】:How do I purge/delete messages of a specific user in a channel如何清除/删除频道中特定用户的消息
【发布时间】:2020-11-22 17:25:26
【问题描述】:

所以我想创建一个命令,该命令可以删除该频道中特定用户的消息,该频道已写入该命令。

我想要的命令:

!clear <user> <no of messages>

例如:!clear @tom 10

我的代码:

@client.command()
async def clear(ctx,  member: discord.Member, user, amt=5+1):
    await ctx.member.purge(limit=amt)
    await ctx.send(f"cleared **{amt-1}** messages", delete_after=2)

我可能还没有接近回答我的问题,但我试过了。

任何帮助将不胜感激

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    我认为这应该可以完成工作:

    @client.command()
    async def clear(ctx,  member: discord.Member, number : int):
        await ctx.message.delete()
        async for msg in ctx.channel.history(limit=number).filter(lambda m: m.author == member).map(lambda m: m):
            try:
                await msg.delete()
            except:
                pass
    

    我所做的是检查消息作者是否与我们提到的用户相等,如果相等则删除他的消息以限制我们想要的数量。

    【讨论】:

      猜你喜欢
      • 2019-06-13
      • 2022-01-12
      • 1970-01-01
      • 2020-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-11
      • 2021-01-27
      相关资源
      最近更新 更多