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)
const { SlashCommandbuilder } = require("@discordjs/builders");
module.exports = {
data: new SlashCommandbuilder()
.setName("ping")
.setDescription("Pong."),
async execute(interaction)
{
interaction.reply("Pong!");
}
}
Codding (commands/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. But before that there was an error in the main code (index.js) that is needed for this "CommandBuilder". 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. Like SlashCommandBuilder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.