所以我收到但找不到的錯誤是在空格后接受任何參數(shù)作為有效命令。我相信這可能是一個.split()錯誤,因為如果您完全匹配參數(shù),它將產(chǎn)生不同的輸出?,F(xiàn)在,如果您使用未列出的參數(shù),它仍會生成原始命令!qa=!qa mollusk當(dāng)參數(shù)通過但不存在時,它應(yīng)該返回一個錯誤,但沒有這樣做。這是我的索引和與復(fù)制相關(guān)的所有內(nèi)容: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 個空格,它會執(zhí)行它。這是我正在構(gòu)建的模塊:我是否認(rèn)為它是在中找到的.split()?這讓我很困惑,也許我忽略了它,它也對沒有任何參數(shù)的常規(guī)命令做同樣的事情。這導(dǎo)致相信我這是在index。?qa alksjdkalsjd如果進行了未指定為 arg 的其他輸入(如 ),我希望它簡單地返回。Discord.js = v12
Discord.js v12,在命令并執(zhí)行后讀取 args 的潛在拆分錯誤
莫回?zé)o
2023-02-24 17:07:01