如何在 discord.py 中使命令不区分大小写

2022-01-14 00:00:00 python python-3.x discord discord.py

问题描述

如何在不为不同的大写字母添加许多别名的情况下使命令不区分大小写,如下所示:

How would one make a command case-insensitive without adding many aliases for different capitalizations like this:

@bot.command(pass_context = True, name = 'test', aliases=['Test', 'tEst', 'teSt', 'tesT', 'TEst', 'TeSt', 'TesT', 'tESt', 'tEsT'])
async def test(self, ctx):
    #do stuff      


解决方案

在重写分支上,commands.Bot 接受 case_insensitive参数

On the rewrite branch, commands.Bot accepts a case_insensitive parameter

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

请注意,使用此功能时会有性能损失.

Note that there is a performance loss when using this feature.

相关文章