如何使命令前缀不区分大小写

时间:2021-01-06 10:59:17

标签: discord.py python-3.7

所以我正在制作我的不和谐机器人,它有点机密代码,所以我想知道如何使命令前缀不区分大小写。非常感谢您的回答!

这是一些代码:

prefixez = json.loads(open('info.json', 'r').read())["prefixes"]
bot = commands.Bot(command_prefix=prefixez, case_insensitive=True)

1 个答案:

答案 0 :(得分:0)

因此,如果您的前缀中有一个字母,例如 g!f.,但您希望这些前缀的大写版本都能使用,请确保有一个数组/列表带有您希望允许的所有前缀。像这样:

client = commands.Bot(command_prefix=['prefix1', 'prefix2'])
# You can just put the lowercase and upper case version in the list/array

但是,假设您有一个可自定义的前缀。嗯,完成同样的事情并不难:

# Make sure you have your normal prefix stored in a variable
# Here, I am keeping my prefix in the "prefix" variable
upper_prefix = prefix.upper()

client = commands.Bot(command_prefix=[prefix, upper_prefix])