gpt4 book ai didi

discord.js - 错误: Invalid string format | const command = require (`${file}` );

转载 作者:行者123 更新时间:2023-12-02 01:35:35 26 4
gpt4 key购买 nike

尝试了很多方法还是没有成功...

这是错误:

Error: Invalid string format
at Object.run (/home/runner/discordgame-1/node_modules/@sapphire/shapeshift/dist/index.js:1281:64)
at /home/runner/discordgame-1/node_modules/@sapphire/shapeshift/dist/index.js:113:66
at Array.reduce (<anonymous>)
at StringValidator.parse (/home/runner/discordgame-1/node_modules/@sapphire/shapeshift/dist/index.js:113:29)
at validateName (/home/runner/discordgame-1/node_modules/@discordjs/builders/dist/index.js:885:17)
at MixedClass.setName (/home/runner/discordgame-1/node_modules/@discordjs/builders/dist/index.js:957:5)
at Object.<anonymous> (/home/runner/discordgame-1/commands/ping.js:5:6)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

代码:

for (const file of commandFiles) {
const command = require(`${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}

const command = require(${file}); 肯定有问题

我第一次使用 stackoverflow,因为我真的找不到解决方案。

如果您想了解有关此问题的更多信息,请询问我。

最佳答案

我在学习discordjs时遇到了同样的问题。我试图创建一些不和谐的命令,问题是我在 setName() 中为命令选择的名称,我使用的是大写字母:

module.exports = {
data: new SlashCommandBuilder()
.setName('membersQuantity') // the uppercase Q is the problem
.setDescription('members quantity'),
async execute(interaction) {
await interaction.reply('test');
},
};

所以我只是改变了它:

module.exports = {
data: new SlashCommandBuilder()
.setName('membersquantity') //no uppercase characters anymore
.setDescription('members quantity'),
async execute(interaction) {
await interaction.reply('test');
},
};

它解决了我的问题。

斜杠命令的名称中可能有更多不允许的字符,因此我建议始终仅使用小写字符。

关于discord.js - 错误: Invalid string format | const command = require (`${file}` );,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72471630/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com