0
votes

So I want to make my bot allow specific messages, like "/verify" in a specifc channel, if someone sent a message other than "verify" the bot should delete the message, however only in a specific channel, I'm new to all of that but I made this code and it's not working

async def verify(ctx):
    user = ctx.message.author 
    role = 'Member' #change the role here
    try:
        await user.add_roles(discord.utils.get(user.guild.roles, name=role)) 
        await ctx.send('Welcome to our server! :white_check_mark:', delete_after=1)
    except Exception as e:
        await ctx.send('Cannot assign role. Error: ' + str(e))
    if not msg.content == '/verify':
        await client.delete_message(msg)

    await ctx.message.delete()

any help would be much appreciated.

2

2 Answers

0
votes

You can just write a simple check right at the beginning of the function. For example,

@bot.command()
async def verify(ctx):
    if ctx.channel.name != "verify":
        return

    # rest of the code

Also, you have not defined msg in your code. So that'll also raise an error

0
votes

You have to specify what exactly your "msg" is that you want to delete. So instead of msg.delete it should be enough to instead write:

if ctx.message.content == "verify":
   await ctx.message.delete

Because the ctx/context is where you get the information about what kind of message it is, which channel it was posted in and so on.