Command Case Insensitve

不问归期 提交于 2019-12-11 08:04:22

问题


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:


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)


来源:https://stackoverflow.com/questions/50525752/command-case-insensitve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!