[英]TypeError (discord.js v14) - SlashCommandbuilder is not a constructor
Terminal error:终端错误:
\commands\ping.js:4
data: new SlashCommandbuilder()
^
TypeError: SlashCommandbuilder is not a constructor
at Object.<anonymous> (D:\MichelDev\Pessoais JM\Relphi (BOT)\commands\ping.js:4:11)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (D:\MichelDev\Pessoais JM\Relphi (BOT)\index.js:20:21)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
Codding (commands/ping.js)编码(命令/ping.js)
const { SlashCommandbuilder } = require("@discordjs/builders");
module.exports = {
data: new SlashCommandbuilder()
.setName("ping")
.setDescription("Pong."),
async execute(interaction)
{
interaction.reply("Pong!");
}
}
Codding (commands/index.js)编码(命令/index.js)
require("dotenv").config();
const fs = require("fs");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v10");
const { Client, GatewayIntentBits, Collection } = require("discord.js");
//const config = ("./config.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages
]
});
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
const commands = [];
client.commands = new Collection();
for (const file of commandFiles)
{
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
client.once("ready", () =>
{
console.log("(Discord.js v14) Ralphi online!");
const CLIENT_ID = client.user.id;
const rest = new REST
({
version: "10"
}).setToken(process.env.TOKEN);
(async () =>
{
try {
if(process.env.ENV === "production")
{
await rest.put(Routes.applicationCommands(CLIENT_ID),
{
body: commands
});
console.log("Comandos registrados com sucesso (global).");
}
else
{
await rest.put(Routes.applicationGuildCommands(CLIENT_ID, process.env.GUILD_ID),
{
body: commands
});
console.log("Comandos registrados com sucesso (local).");
}
}
catch(err)
{
if(err) console.error(err);
}
})();
});
client.login(process.env.TOKEN);
I'm creating a bot for the first time on discord.js (v14) and using it as a way of learning, but when I started to assemble these "SlashCommandBUilder", it wasn't.我第一次在 discord.js (v14) 上创建一个机器人并将其用作一种学习方式,但是当我开始组装这些“SlashCommandBUilder”时,它不是。 But before that there was an error in the main code (index.js) that is needed for this "CommandBuilder".但在此之前,此“CommandBuilder”所需的主代码 (index.js) 中存在错误。 I don't know what else to do, so I ask you to help me.我不知道还能做什么,所以我请你帮助我。 Thank you very much in advance.非常感谢您提前。
I think the letter B in the builder part (SlashCommandbuilder) should be uppercase.我认为构建器部分(SlashCommandbuilder)中的字母 B 应该是大写的。 Like SlashCommandBuilder像 SlashCommandBuilder
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.