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

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.

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会
问题描述: 在javascript中引用js代码,然后导致反斜杠丢失,发现字符串中的所有\信息丢失。比如在js中引用input type=text onkeyup=value=value.replace(/[^\d]/g,) ,结果导致正则表达式中的\丢失。 问题原因: 该字符串含有\,javascript对字符串进行了转
Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
Ordinals in words javascript(javascript中的序数)
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)