使用不和谐按钮时出错:"Class extends value undefined is not a constructor or null"
Error using discord-buttons: "Class extends value undefined is not a constructor or null"
我试图在 Discord.js 中制作一个按钮。但是,当我写代码的时候,发现启动的时候出错了。
我不知道为什么会出现这个错误。网上查了很多相关的问题,但是none的问题都解决了,我更糊涂了
这是我的代码:
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)
这是错误信息:
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)
在 Discord.js v13 中,API message class has been renamed to MessagePayload。 APIMessage
因此会是 undefined
.
此错误发生在 discord-buttons
模块中。 Discord.js v13 支持按钮,所以你不需要这个模块。有关详细信息,请参阅 Discord.js guide on buttons。
要发送按钮,您可以使用此代码:
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])]
});
}
});
您还应该看看 Discord.js v13 upgrade guide。
我试图在 Discord.js 中制作一个按钮。但是,当我写代码的时候,发现启动的时候出错了。
我不知道为什么会出现这个错误。网上查了很多相关的问题,但是none的问题都解决了,我更糊涂了
这是我的代码:
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)
这是错误信息:
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)
在 Discord.js v13 中,API message class has been renamed to MessagePayload。 APIMessage
因此会是 undefined
.
此错误发生在 discord-buttons
模块中。 Discord.js v13 支持按钮,所以你不需要这个模块。有关详细信息,请参阅 Discord.js guide on buttons。
要发送按钮,您可以使用此代码:
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])]
});
}
});
您还应该看看 Discord.js v13 upgrade guide。