on_message() and @bot.command issue

前端 未结 1 528
醉酒成梦
醉酒成梦 2020-12-06 15:55

When I have on_message() in my code, it stops every other @bot.command commands from working. I\'ve tried to await bot.process_commands(messa

相关标签:
1条回答
  • 2020-12-06 16:05

    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)
    

        

    0 讨论(0)
提交回复
热议问题