discord.js v13 -无法使用交互选项



在过去的一段时间里,我一直在尝试做一个"评估";命令。
我有一个系统,随着我的命令处理程序,然而,它是特别的"Eval"导致问题的命令

我目前正在使用@discordjs/builders,然而,它没有帮助。
斜杠命令是这样构建的:

slash: new SlashCommandBuilder()
.setName("eval")
.setDescription("Evaluates JavaScript code.")
.addStringOption(option => option.setName("code").setDescription("Your JavaScript code.").setRequired(true)),

在Discord中,"代码"选项甚至都没有出现。当我尝试运行命令时,输入:

/eval ```js
console.log("Hello World");

我得到一个错误说Cannot read property "replace" of null
这是斜杠命令的脚本:

runSlash: async (interaction, bot) => {
if (interaction.user.id !== interaction.guild.ownerId) {
interaction.reply("You are not allowed to do this.");
return bot.commandLog(`${msg.author} attempted to use the EVAL command, but was not Atelo.`);
}
const toEval = interaction.options.getString("code");
console.log(interaction.options);
/*
this is what ^^^ returns:
CommandInteractionOptionResolver {
_group: null,
_subcommand: null,
_hoistedOptions: []
}
*/
console.log(interaction.options.getString("code")); // Also returns null
const toRemove = /^(```js)|(```)$/gi;
const evalEmbed = new MessageEmbed();
try {
const evalled = eval(toEval.replace(toRemove, ''));
evalEmbed.setTitle("Evaluation Successful");
evalEmbed.addFields({ name: "Output", value: "```jsn" + evalled + "n```" });
evalEmbed.setFooter(interaction.guild.name, interaction.guild.iconURL());
evalEmbed.setTimestamp();
} catch (err) {
evalEmbed.setTitle("Evaluation Failed");
evalEmbed.addFields({ name: "Output", value: "```jsn" + err + "n```" });
evalEmbed.setFooter(interaction.guild.name, interaction.guild.iconURL());
evalEmbed.setTimestamp();
}
interaction.reply({ embeds: [evalEmbed] });
return bot.commandLog(`${msg.author} successfully used the EVAL command.`);
}
}

我试着调试了一段时间,我非常困惑。谢谢你提供的任何帮助!

所以,我意识到我在命令处理程序中使用了错误的变量,它破坏了斜杠命令。

哦!

最新更新