Command Case Insensitve

2019-08-02 06:27发布

How to make below command to work if members use below command in lower or upper or mixing. If members use ping it works. but if members use Ping it not works.

@bot.event
async def on_message(message):
    message.content = message.content.lower()
    await bot.process_commands(message)

    @bot.command(pass_context=True)
    async def ping(ctx):
        msg = 'Pong {0.author.mention}'.format(ctx.message)
        await bot.say(msg)

Update:

above on_message is working correctly in single file but i splitted main file to multiple files. now how to make it work for cog in all files.

1条回答
Deceive 欺骗
2楼-- · 2019-08-02 07:21

You can pass a case_insensitive option to your Bot when you create it.

from discord.ext import commands

bot = commands.Bot('!', case_insensitive=True)

@bot.command(pass_context=True)
async def ping(ctx):
    msg = 'Pong {0.author.mention}'.format(ctx.message)
    await bot.say(msg)
查看更多
登录 后发表回答