所以我收到但找不到的错误是在空格后接受任何参数作为有效命令。我相信这可能是一个.split()错误,因为如果您完全匹配参数,它将产生不同的输出。现在,如果您使用未列出的参数,它仍会生成原始命令!qa=!qa mollusk当参数通过但不存在时,它应该返回一个错误,但没有这样做。这是我的索引和与复制相关的所有内容:const fs = require('fs');const Discord = require('discord.js');const { prefix, token } = require('./config.json');const featureFiles = fs.readdirSync('./commands/features').filter(file => file.endsWith('.js'));for (const file of featureFiles) { const command = require(`./commands/features/${file}`); client.commands.set(command.name, command);} client.on('message', message => { if (!message.content.startsWith(prefix) || message.author.bot) return;//.trim() is removed, see notes below on why const args = message.content.slice(prefix.length).split(/ +/g); const commandName = args.shift().toLowerCase(); const command = client.commands.get(commandName) || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); if (!command) return; if (command.guildOnly && message.channel.type !== 'text') { return message.reply('That command cannot be used inside a DM'); } if (command.args && !args.length) { let reply = `You didn't provide any arguments!`; if (command.usage) { reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``; } return message.channel.send(reply); } try { command.execute(message, client, args); } catch (error) { console.error(error); message.channel.send('Error trying to execute command'); }});client.login(token);我删除了.trim()它,因为它正在读取前缀和命令名称之间的空格,这是我不想要的,所以可以在前缀和命令之间使用 100 个空格,它会执行它。这是我正在构建的模块:我是否认为它是在中找到的.split()?这让我很困惑,也许我忽略了它,它也对没有任何参数的常规命令做同样的事情。这导致相信我这是在index。?qa alksjdkalsjd如果进行了未指定为 arg 的其他输入(如 ),我希望它简单地返回。Discord.js = v12
1 回答
POPMUISE
TA贡献1765条经验 获得超5个赞
你想要做的是像这样重组你的 if :
if(args.length === 0) { // this runs everytime there are no args provided
return message.channel.send(data, 'To see focus types, type `!qa [arg]`, example `!qa test`', { split: true });
}
if (args[0] === 'test') {
return message.channel.send(testing)
}
/* ........... */
return message.channel.send(error); // send a errror here if the args were not handled by the above cases
添加回答
举报
0/150
提交
取消