首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >由于类扩展值未定义不是构造函数或为空,Discord bot出现错误

由于类扩展值未定义不是构造函数或为空,Discord bot出现错误
EN

Stack Overflow用户
提问于 2021-08-29 12:02:58
回答 1查看 655关注 0票数 0

所以我想做一个帮助嵌入到一个频道中,但是当我开始运行它的时候,它并没有像我想象的那样工作……我已经看过了,但我找不到任何问题..如果有人可以帮助我,请帮助我。我知道这段代码有点奇怪。我正在使用的包:

代码语言:javascript
复制
@discordjs/rest 0.1.0-canary.0,
discord-api-types 0.22.0,
discord-buttons 4.0.0,
discord.js 13.1.0
i 0.3.6
npm 7.21.1

这是我在使用node时得到的错误。

代码语言:javascript
复制
C:\Users\emilb\OneDrive\Desktop\Carly Support Center\node_modules\discord-buttons\src\v12\Classes\APIMessage.js:9
class sendAPICallback extends dAPIMessage {
                              ^
TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (C:\Users\emilb\OneDrive\Desktop\Carly Support Center\node_modules\discord-buttons\src\v12\Classes\APIMessage.js:9:31)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153: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:94:18)
    at Object.<anonymous> (C:\Users\emilb\OneDrive\Desktop\Carly Support Center\node_modules\discord-buttons\src\v12\Classes\WebhookClient.js:2:20)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

这是index.js

代码语言:javascript
复制
const { Client, Intents, MessageActionRow, MessageButton } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

//Importing Rest & api-types
const { REST } = require('@discordjs/rest')
const { Routes } = require('discord-api-types/v9')

//Loading Config
const config = require('./config.json');
const { default: discordButtons } = require('discord-buttons');
console.log('Config Loaded')
var owners = config.owners

//Ready Event
client.on('ready', async () => {
    console.log(`${client.user.tag} is Ready!`)

    client.user.setPresence({
        status: "online",
        activities: [{
            name: config.status,
            type: "LISTENING",
        }]
    })
    
    //Registering Slash
    if (config.enable_slash) {
        const rest = new REST({ version: '9' }).setToken(config.token)

        const commands = [{
            name: 'create',
            description: 'Replies with Help Embed!'
        }]
        
        try {
            console.log('Started refreshing application (/) commands.')
            
            await rest.put(
                Routes.applicationCommands(client.user.id),
                { body: commands },
            );

            console.log('Successfully reloaded application (/) commands.')
        }
        catch (error) {
            console.error(error)
        }
    }
})

/**
 * @author Emiluvik#8447 <https://github.com/Emiluvik>
 */

client.on("interactionCreate", async (interaction) => {
    var SupportEmbed = 
    {
        author: { name: config.embed_content.title, icon_url: client.user.displayAvatarURL({ size: 2048, dynamic: false, format:"png"}) },
        timestamp: new Date(),
        color: `0x${config.embed_content.color}`,
        thumbnail: { url: config.thumbnail ? config.thumbnail_url : client.user.displayAvatarURL({ size: 2048, format: "png", dynamic: false}) },
        description: `\u200b\n1️⃣ ${config.embed_content.question_1}\n\u200b\n2️⃣ ${config.embed_content.question_2}\n\u200b\n3️⃣ ${config.embed_content.question_3}\n\u200b\n4️⃣ ${config.embed_content.question_4}\n\u200b\n5️⃣ ${config.embed_content.question_5}\n\u200b\n> **None Of The Above**\nIf Your Question is not in the Above List.(Further Assistance)\n\u200b\n`,
        footer:{
            text: interaction.guild.name
        }
    }
    let button1 = new MessageButton()
        .setStyle("SECONDARY")
        .setEmoji("1️⃣")
        .setCustomId("button_one")

    let button2 = new MessageButton()
        .setEmoji("2️⃣")
        .setStyle("SECONDARY")
        .setCustomId("button_two")
        
    let button3 = new MessageButton()
        .setEmoji("3️⃣")
        .setStyle("SECONDARY")
        .setCustomId("button_three")
    
    let button4 = new MessageButton()
        .setEmoji("4️⃣")
        .setStyle("SECONDARY")
        .setCustomId("button_four")
 
    let button5 = new MessageButton()
        .setEmoji("5️⃣")
        .setStyle("SECONDARY")
        .setCustomId("button_five")

    let button6 = new MessageButton()
        .setLabel("None Of The Above")
        .setStyle("SUCCESS")
        //.setEmoji("??‍♂️")
        .setCustomId("none_of_the_above")
    
    let buttonRow1 = new MessageActionRow()
        .addComponents([button1, button2, button3, button4, button5])
    
    let buttonRow2 = new MessageActionRow()
        .addComponents([button6])
    
    if (interaction.isCommand()) {
        if (!owners.includes(interaction.user.id)) {
            await interaction.reply({ content: "You aren\'t Authorized To use This Command!", ephemeral: true })
        }

        await interaction.reply({ embeds: [SupportEmbed], components: [buttonRow1, buttonRow2] })
    }
    else if (interaction.isButton()) {
        let responseembed = 
        {
            author:{ name: config.title, icon_url: config.thumbnail ? config.thumbnail_url : client.user.displayAvatarURL({ size: 2048, format: "png", dynamic: false}) },
            color: `0x${config.embed_content.color}`,
            description: null,
            timestamp: new Date(),
            footer:{
                text: interaction.guild.name
            }
        }
        const logchannel = interaction.guild.channels.cache.get(config.log_channel_id)
        if (interaction.customId === "button_one") {
            responseembed.description = `\u200b\n**${config.responses.response_1}**\n\u200b\n`
            logchannel.send(`> **${interaction.user.username + "#" + interaction.user.discriminator}**(${interaction.user.id}) Used ${interaction.customId}\nTimeStamp: ${new Date()}`)
            // let invitecutie = new MessageButton()
            //     .setLabel("Invite Link")
            //     .setStyle("url")
            //     .setURL("Link")
            // let buttonRow = new MessageActionRow()
            //  .addComponent(invitecutie)
            //!If You Want Button in the Response remove // from the the Above 6 lines
            return interaction.reply({ embeds: [responseembed], ephemeral: true })//If you want to send link button add ,component: buttonRow after the ephermeral: true declaration
        }
        if (interaction.customId === "button_two") {
            responseembed.description = `**${config.responses.response_2}**\n\u200b\n`
            logchannel.send(`> **${interaction.user.username + "#" + interaction.user.discriminator}**(${interaction.user.id}) Used ${interaction.customId}\nTimeStamp: ${new Date()}`)
            return interaction.reply({ embeds: [responseembed], ephemeral: true })
        }
        if (interaction.customId === "button_three") {
            responseembed.description = `**${config.responses.response_3}**`
            logchannel.send(`> **${interaction.user.username + "#" + interaction.user.discriminator}**(${interaction.user.id}) Used ${interaction.customId}\nTimeStamp: ${new Date()}`)
            return interaction.reply({ embeds: [responseembed], ephemeral: true })
        }
        if (interaction.customId === "button_four") {
            responseembed.description = `**${config.responses.response_4}**`
            logchannel.send(`> **${interaction.user.username + "#" + interaction.user.discriminator}**(${interaction.user.id}) Used ${interaction.customId}\nTimeStamp: ${new Date()}`)
            return interaction.reply({ embeds: [responseembed], ephemeral: true })
        }
        if (interaction.customId === "button_five") {
            responseembed.description = `**${config.responses.response_5}**`
            logchannel.send(`> **${interaction.user.username + "#" + interaction.user.discriminator}**(${interaction.user.id}) Used ${interaction.customId}\nTimeStamp: ${new Date()}`)
            return interaction.reply({ embeds: [responseembed], ephemeral: true })
        }
        if (interaction.customId === "none_of_the_above") {
            responseembed.description = `**Go to <#${config.assistance_channel_id}> Channel and ask Your Questions.**`
            interaction.guild.members.cache.get(interaction.user.id).roles.add('856799419402813440')
            interaction.guild.channels.cache.get(config.assistance_channel_id).send(`<@${interaction.user.id}> Here you can Ask your Further Questions.`)
            logchannel.send(`> **${interaction.user.username + "#" + interaction.user.discriminator}**(${interaction.user.id}) Used ${interaction.customId}\nTimeStamp: ${new Date()}`)
            return interaction.reply({ embeds: [responseembed], ephemeral: true })
        }
    }
})

client.on("messageCreate", async (msg) => {
    if (msg.author.bot) return
    if (msg.channel.type === "dm") return
    if (!owners.includes(msg.author.id)) return
    if (msg.content !== `${config.prefix}create`) return
    if (msg.content = `${config.prefix}create`) {
        await msg.delete().catch(() => {})
        let button1 = new MessageButton()
            .setStyle("SECONDARY")
            .setEmoji("1️⃣")
            .setCustomId("button_one")

        let button2 = new MessageButton()
            .setEmoji("2️⃣")
            .setStyle("SECONDARY")
            .setCustomId("button_two")
            
        let button3 = new MessageButton()
            .setEmoji("3️⃣")
            .setStyle("SECONDARY")
            .setCustomId("button_three")
        
        let button4 = new MessageButton()
            .setEmoji("4️⃣")
            .setStyle("SECONDARY")
            .setCustomId("button_four")
 
        let button5 = new MessageButton()
            .setEmoji("5️⃣")
            .setStyle("SECONDARY")
            .setCustomId("button_five")

        let button6 = new MessageButton()
            .setLabel("None Of The Above")
            .setStyle("SUCCESS")
            //.setEmoji("??‍♂️")
            .setCustomId("none_of_the_above")
        
        let buttonRow1 = new MessageActionRow()
            .addComponents([button1, button2, button3, button4, button5])
        
        let buttonRow2 = new MessageActionRow()
            .addComponents([button6])
        
        const supportembed = {
            author: { name: config.embed_content.title, icon_url: client.user.displayAvatarURL({ size: 2048, dynamic: false, format:"png"}) },
            timestamp: new Date(),
            color: `0x${config.embed_content.color}`,
            thumbnail: { url: config.thumbnail ? config.thumbnail_url : client.user.displayAvatarURL({ size: 2048, format: "png", dynamic: false}) },
            description: `\u200b\n1️⃣ ${config.embed_content.question_1}\n\u200b\n2️⃣ ${config.embed_content.question_2}\n\u200b\n3️⃣ ${config.embed_content.question_3}\n\u200b\n4️⃣ ${config.embed_content.question_4}\n\u200b\n5️⃣ ${config.embed_content.question_5}\n\u200b\n> **None Of The Above**\nIf Your Question is not in the Above List.(Further Assistance)\n\u200b\n`,
            footer:{
                text: msg.guild.name
            }
        }
        return msg.channel.send({ embeds: [supportembed], components: [buttonRow, buttonRow2] })
    } else return
})

client.login(config.token).catch(() => console.log('Invalid Token.Make Sure To Fill config.json'))

这是config.json..

代码语言:javascript
复制
{
    "token": "Token",
    "status": "cs!help",
    "prefix": "cs!",
    "enable-slash": true,
    "owners": ["468053162729799700"],
    "embed_content": {
        "title": "Carly Support",
        "color": "FFA500",
        "thumbnail": true,
        "thumbnail_url": "profile.png",
        "question_1": "How do I invite Carly?",
        "question_2": "How do I setup Carly?",
        "question_3": "Carly isn't responding",
        "question_4": "How do I make a bug report?",
        "question_5": "How do I suggest a command to Carly?"
    },
    "responses": {
        "response_1": "If you type: [prefix]invite, Carly will you give an invite link!",
        "response_2": "Carly is already set and done! If you wish to change the prefix\nto Carly, type ?prefix [prefix].",
        "response_3": "If Carly isn't responding, it is because, the MongoDb pass failed\nto connect, or it's because the bot is shutting down.",
        "response_4": "If you join the (support center)[https://discord.gg/nB84Fn6VGd]\nyou can make a report a bug!",
        "response_5": "If you join the (support center)[https://discord.gg/nB84Fn6VGd]\nyou can make a suggestion!"
    },
    "log_channel_id": "880869600298954802",
    "assistance_channel_id": "880869600298954802",
    "assistance_role_id": "880870840030351520"
}

我试着安装了不同的npm包,但仍然不能工作。所以我在这里请求帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-29 13:16:11

不一致按钮库目前只支持Discord.js的v12,并依赖于该库中的一个类,这个类在最新版本13中已经不存在了。还有an issue来更新包以支持v13,但看起来这不会很快发生。如果你想使用这个包,要么将你的djs版本降级到v12,要么使用像patch-package这样的工具自己解决这个问题。

希望这能有所帮助;3

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68972697

复制
相关文章

相似问题

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