RexoDev
RexoDev

Reputation: 33

discord.py delete every message

I am making discord verification bot. I have this now:

@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)

I want him to delete every message and specific delete that verify success message after like 5 seconds. Can i do it somehow? and I also want it to delete every other new message, including that command .verify. Can i somehow do it? Thanks.

Upvotes: 1

Views: 99

Answers (1)

moinierer3000
moinierer3000

Reputation: 1979

Sorry, I do not quite understand what exactly you mean, but there are several ways to delete a message after it has been sent.

First is to use the delete_after argument in the send function like this:

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

Secondly you could also delete it manually:

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()

And if you want to delete the message that invoked the command (aka the .verify message), you can use:

await ctx.message.delete()

Hope this answers your question.

Upvotes: 1

Related Questions