Verification channel - Discord.py

Viewed 536

I have a ".verify" command. I have a special channel for verification, and I want to make the bot delete every message but not embeds and the .verify command. Can I somehow do it?

.verify's code:

@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:926853473251778601> Verification", description="You are now Verified!", color=0xe67e22)
    if ctx.channel.id == 926848096862887976:
      await ctx.author.add_roles(MEMBER)
      await ctx.author.remove_roles(UNVER)
      await ctx.message.delete()
      await ctx.send(embed=embed, delete_after=3)
1 Answers

I guess you want to delete messages if their authors are users and the message is not ".verify", or if the author is a bot, but the message doesn't have embeds. You can use ctx.author.bot to check if the author is a bot (returns a boolean) and ctx.embeds to check if the message has embeds (returns a list of embeds in the message, we check if the number of embeds is 0).

@bot.event
async def on_message(ctx):
    user = ctx.author #Just a member, can be a bot or a user. The author of the message.
    if user.bot: #Check if the author is a bot.
        if not ctx.embeds: #Check if embeds are not there in the message.
            print("Deleting because it's a message sent by a bot but doesn't have embeds")
            await ctx.delete()
    elif not user.bot: #Check if the author of the message is a user.
        if ctx.content != ".verify": #Check if the message is not exactly ".verify" (the verify message/command sent by the user).
            print("Deleting because it's not .verify")
            await ctx.delete()

The print() commands are just for your reference and logging. You can delete them if you want better performance. Check the documentation for a better understanding.

Related