【发布时间】:2020-07-29 16:56:31
【问题描述】:
我想让我的机器人命令空间不敏感。每次我做类似“go rps”的事情时,即使 go rps 是一个命令,未知命令的东西仍然会输出。对于像“查看”这样的命令,未知的命令是有效的。我在下面链接了我的代码!我想出了如何使它不区分大小写但不区分空格。
client.on('message', (message) => {
if(!message.content.startsWith(PREFIX)) return;
let validCommands = ["go rps", "go mountains", "go hills", "go cannons", "go left", "go east", "go west", "view", "holler"];
// Added the .toLowerCase() function vvv to make everything work both ways
const args = message.content.toLowerCase().substring(PREFIX.length).slice().split(/ /);;
const command = args.shift();
const isValid = validCommands.includes(command);
const unknowncommand = new Discord.MessageEmbed()
.setColor('GREEN')
.setTitle('SCOTT')
.setDescription('You\'ve entered an unknown command. \nUse **!help** to see all available commands.')
if(!isValid){
if(message.author.bot) return;
return message.channel.send(unknowncommand), console.log(`[SCOTT] ${message.author.username} entered an unknown command in "${message.guild.name}".`);
}
});
这个代码是我几个小时前在网上找到的。唯一有效的。有人可以帮我获得间距的,比如“go rps”应该可以工作。无论如何,请帮助。谢谢。
【问题讨论】:
-
您需要将命令吐到文件中并使用正则表达式查找命令或命令别名
标签: node.js discord.js