on_message() and @bot.command issue

You have to place await bot.process_commands(message) outside of the if statement scope, process_command should be run regardless if the message startswith ”/lockdown”.

@bot.event
async def on_message(message):
    if message.content.startswith('/lockdown'):
       ...
    await bot.process_commands(message)

By the way, @commands.has_role(...) cannot be applied to on_message. Although there aren’t any errors (because there’s checking in place), has_role wouldn’t actually work as you would’ve expected.

An alternative to the @has_role decorator would be:

@bot.event
async def on_message(message):
    if message.channel.is_private or discord.utils.get(message.author.roles, name="Admin") is None:
        return False

    if message.content.startswith('/lockdown'):
       ...
    await bot.process_commands(message)

    

Leave a Comment