【问题标题】:discord.py delete every messagediscord.py 删除每条消息
【发布时间】:2022-01-02 04:46:22
【问题描述】:

我正在制作不和谐的验证机器人。我现在有这个:

@bot.command(pass_context=True)
async def verify(ctx):
    MEMBER = discord.utils.get(ctx.guild.roles, name= "♰・Member")
    UNVER = discord.utils.get(ctx.guild.roles, name= "♰・No Verification")
    embed=discord.Embed(title=":oktagon: Verification", description="You are now Verified!", color=0xe67e22)
    await ctx.send(embed=embed)
    await ctx.author.add_roles(MEMBER)
    await ctx.author.remove_roles(UNVER)

@bot.event
async def on_member_join(member):
    UNVEREFE = discord.utils.get(ctx.guild.roles, name= "♰・No Verification")
    await ctx.author.add_roles(UNVEREFE)

我希望他在 5 秒后删除每条消息并具体删除验证成功消息。我能以某种方式做到吗?而且我还希望它删除所有其他新消息,包括该命令 .verify。我能以某种方式做到吗?谢谢。

【问题讨论】:

    标签: python discord discord.py bots


    【解决方案1】:

    对不起,我不太明白你的意思,但是有几种方法可以在消息发送后删除。

    首先是在send 函数中使用delete_after 参数,如下所示:

    embed=discord.Embed(title=":oktagon: Verification", description="You are now Verified!", color=0xe67e22)
    await ctx.send(embed=embed, delete_after=5.0)
    

    https://discordpy.readthedocs.io/en/master/api.html?highlight=send#discord.abc.Messageable.send

    其次你也可以手动删除:

    import asyncio
    
    embed=discord.Embed(title=":oktagon: Verification", description="You are now Verified!", color=0xe67e22)
    embed_message = await ctx.send(embed=embed)
    await asyncio.sleep(5)
    await embed_message.delete()
    

    如果你想删除调用命令的消息(又名.verify 消息),你可以使用:

    await ctx.message.delete()
    

    希望这能回答你的问题。

    【讨论】:

      猜你喜欢
      • 2018-06-29
      • 2021-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2021-09-26
      • 1970-01-01
      • 1970-01-01
      • 2020-07-21
      相关资源
      最近更新 更多