簡體   English   中英

TypeError (discord.js v14) - SlashCommandbuilder 不是構造函數

[英]TypeError (discord.js v14) - SlashCommandbuilder is not a constructor

終端錯誤:

    \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)

編碼(命令/ping.js)

const { SlashCommandbuilder } = require("@discordjs/builders"); 
module.exports = {
    data: new SlashCommandbuilder()
        .setName("ping")
        .setDescription("Pong."),
    async execute(interaction)
    {
        interaction.reply("Pong!"); 
    }
}

編碼(命令/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);

我第一次在 discord.js (v14) 上創建一個機器人並將其用作一種學習方式,但是當我開始組裝這些“SlashCommandBUilder”時,它不是。 但在此之前,此“CommandBuilder”所需的主代碼 (index.js) 中存在錯誤。 我不知道還能做什么,所以我請你幫助我。 非常感謝您提前。

我認為構建器部分(SlashCommandbuilder)中的字母 B 應該是大寫的。 像 SlashCommandBuilder

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM