有没有办法使我的前缀不区分大小写(Discord.js) [英] Is there a way to make my prefix non case sensitive (Discord.js)
问题描述
我正在制造一个不和谐的机器人,我的前缀是xok,当前使用的代码可以使它正常运行,因此xok始终必须写为"xok",如果我能够做到,我认为这将极大地改善生活质量更改它,但我无法真正看到如何使用当前代码,我们将不胜感激!
Im making a discord bot and my prefix is xok, the code im currently using makes it so the xok always has to be written as "xok", I think it would be a massive quality of life improvement if i were able to change it, but i cant really see how i could using the current code, any help is appreciated!
(message.content.indexOf(client.config.prefix)!== 0)返回;
(message.content.indexOf(client.config.prefix) !== 0) return;
我的前缀"config.json"文件vv中的代码
The code in my prefix "config.json" file vv
{令牌":"*我的令牌","prefix":"xok"}
{ "token": "*my Token", "prefix": "xok" }
推荐答案
只需测试小写的邮件内容,而不是大小写不同的邮件内容:
Simply test the lowercased message content instead of the varying cased one:
if(!message.content.toLowerCase().startsWith(client.config.prefix)) return;
通过这种方式,无论输入的前缀是什么大小写,它都将始终输入该函数的其余部分.
that way regardless of what casing the prefix was entered with, it will always enter the rest of the function.
这篇关于有没有办法使我的前缀不区分大小写(Discord.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!