discord.py 删除每条消息

discord.py delete every message

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

@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。我能以某种方式做到吗?谢谢

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

首先是在 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()

希望这能回答您的问题。