使用不和谐按钮时出错:“类扩展值未定义不是构造函数或空值"

Error using discord-buttons: quot;Class extends value undefined is not a constructor or nullquot;(使用不和谐按钮时出错:“类扩展值未定义不是构造函数或空值)
本文介绍了使用不和谐按钮时出错:“类扩展值未定义不是构造函数或空值"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

I tried to make a button in Discord.js. However, when I wrote the code, I found that there was an error during startup.

I don't know why this error is happening. I checked many related questions online, but none of my problems were solved, and I even became even more confused.

This is my code:

const config = require("./config.json");
const Discord = require('discord.js');
const bot = new Discord.Client();
require('discord-buttons')(client);
const fs = require("fs");
const client = new Discord.Client({disableEveryone: false});
const moment = require("moment");
const { MessageButton, MessageActionRow } = require('discord-buttons')

client.commands = new Discord.Collection();

fs.readdir("./commands/", (err, files) => {

  if(err) console.log(err);
  let jsfile = files.filter(f => f.split(".").pop() === "js");
  if(jsfile.length <= 0){
    console.log("XX");
    return;
  }
  jsfile.forEach((f, i) =>{
    let props = require(`./commands/${f}`);
    client.commands.set(props.help.name, props);
  });
});

    client.on('message', async message => {
      if(message.content === "buttonstest"){
      const button = new MessageButton()
      .setLabel("test")
      .setStyle("green")
      .setID("btn1")
      var embed = new Discord.RichEmbed()
  .setColor("#FFFFFF")
  .setTitle("test")
    
      message.channel.send(embed, button);
      }
    })
        
client.on("message", async message => {
  if(message.author.bot) return;
  if(message.channel.type === "dm") return;

  let prefix = config.prefix;
  let messageArray = message.content.split(" ");
  let cmd = messageArray[0];
  let args = messageArray.slice(1);
  let commandfile = client.commands.get(cmd.slice(prefix.length));
  if(commandfile) commandfile.run(client,message,args);
});

client.login(config.token)

This is the error message:

I have no name!@f7808405-1373-45ee-bac7-0059f94bd574:~$ /home/container/node_modules/discord.js-buttons/src/Classes/APIMessage.js:5
class sendAPICallback extends APIMessage {
                              ^

TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/home/container/node_modules/discord.js-buttons/src/Classes/APIMessage.js:5:31)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Module.require (internal/modules/cjs/loader.js:957:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/home/container/node_modules/discord.js-buttons/src/Classes/Message.js:3:20)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)

解决方案

In Discord.js v13, the API message class has been renamed to MessagePayload. APIMessage would therefore be undefined.

This error is occurring in the discord-buttons module. Discord.js v13 supports buttons so you do not need this module. See the Discord.js guide on buttons for more details.

To send a button, you could use this code:

client.on('message', async message => {
  if(message.content === "buttonstest"){
    const button = new Discord.MessageButton()
      .setLabel("test")
      .setStyle("SUCCESS")
      .setCustomId("btn1");
    // Note that RichEmbed was renamed to MessageEmbed in v12
    const embed = new Discord.MessageEmbed()
      .setColor("#FFFFFF")
      .setTitle("test");
    message.channel.send({
      embeds: [embed],
      components: [{components: [button]}]
      // alternatively
      // components: [new Discord.MessageActionRow([button])] 
    });
  }
});

You should also take a look at the Discord.js v13 upgrade guide.

这篇关于使用不和谐按钮时出错:“类扩展值未定义不是构造函数或空值"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Should I use window.navigate or document.location in JavaScript?(我应该在 JavaScript 中使用 window.navigate 还是 document.location?)
Power BI - Get data from post request(Power BI - 从发布请求中获取数据)
Embed a Power BI report in React JS to get report instance(在 React JS 中嵌入 Power BI 报表以获取报表实例)
Create Report in Embed View via PowerBI API(通过 PowerBI API 在嵌入视图中创建报表)
Interactive Dialog Box in PowerBI(PowerBI 中的交互式对话框)
Print/Generate PDF of embedded power bi report(打印/生成嵌入式 power bi 报告的 PDF)