如何在 discord.py 中使命令不区分大小写 [英] How to make a command case insensitive in discord.py

查看:11
本文介绍了如何在 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.

这篇关于如何在 discord.py 中使命令不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆