首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“'const command=require”抛出一个错误

“'const command=require”抛出一个错误
EN

Stack Overflow用户
提问于 2022-11-13 11:36:03
回答 1查看 43关注 0票数 -2

这是密码-

代码语言:javascript
复制
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    commands.push(command.data.toJSON());

第二行是试图连接到文件- /commands/hi.js

这就是hi.js所包含的内容

代码语言:javascript
复制
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('Hi')
        .setDescription('Get introduced to the bot'),
    async execute(interaction) {
        await interaction.reply('Hi I am Herote bot I was created by a Dog names barood /help for commands');
    },
};

这就是错误

代码语言:javascript
复制
    throw this.error;
    ^

ExpectedConstraintError: Invalid string format
    at Object.run (C:\Users\ranja\Desktop\Discord bot\node_modules\@sapphire\shapeshift\dist\index.js:1549:64)
    at C:\Users\ranja\Desktop\Discord bot\node_modules\@sapphire\shapeshift\dist\index.js:113:66
    at Array.reduce (<anonymous>)
    at StringValidator.parse (C:\Users\ranja\Desktop\Discord bot\node_modules\@sapphire\shapeshift\dist\index.js:113:29)
    at validateName (C:\Users\ranja\Desktop\Discord bot\node_modules\@discordjs\builders\dist\index.js:819:17)
    at MixedClass.setName (C:\Users\ranja\Desktop\Discord bot\node_modules\@discordjs\builders\dist\index.js:895:5)
    at Object.<anonymous> (C:\Users\ranja\Desktop\Discord bot\commands\Hi.js:5:4)
    at Module._compile (node:internal/modules/cjs/loader:1159:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
    at Module.load (node:internal/modules/cjs/loader:1037:32) {
  constraint: 's.string.regex',
  given: 'Hi',
  expected: 'expected /^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{N}\\p{sc=Devanagari}\\p{sc=Thai}_-]+$/u.test(expected) to be true'
}

它应该只是运行应用程序后,连接,但我得到了这个错误。我正在使用Node.js/npm模块/Discord.js的最新版本

EN

回答 1

Stack Overflow用户

发布于 2022-11-13 12:49:49

您获得此特定错误的原因是您试图将命令名大写为大写,而使用斜杠命令是不可能的。另外,还需要注意的是,您也不能大写命令选项。

只需将其改为:

代码语言:javascript
复制
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('hi')
        .setDescription('Get introduced to the bot'),
    async execute(interaction) {
        await interaction.reply('Hi I am Herote bot I was created by a Dog names barood /help for commands');
    },
};
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74420563

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档