Discord.js embeds: TypeError: Discord.MessageEmbed is not a constructor
Discord.js embeds: TypeError: Discord.MessageEmbed is not a constructor
我最近尝试为我的 discord 机器人添加 MessageEmbed,但出现此错误:
TypeError: Discord.MessageEmbed is not a constructor
我想知道是否有人知道如何解决这个问题,我已经尝试了一些我可以在网上找到的 rip,一些包括尝试重新安装 node.js 和 discord.js,其他提到不同的方法,比如使用 NewMessageEmbed(),但是 none 一直在为我工作,如果有人比我更有经验可以提供解决方案,我会提供所有涉及的代码和屏幕截图错误,提前致谢。
命令文件:
module.exports = {
name: 'command',
description: "Embeds!",
execute(message, args, Discord){
const newEmbed = new Discord.MessageEmbed()
.setColor('#FFA62B')
.setTitle('Rules')
.setURL('https://discord.gg/fPAsvEey2k')
.setDescription('**This is an embed for the server rules.**')
.addFields(
{name: '1.', value: 'Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism or hate speech will be tolerated.'},
{name: '2.', value: 'No spam or self-promotion (server invites, advertisements, etc.) without permission from a staff member. This includes DMing fellow members.'},
{name: '3.', value: 'No NSFW or obscene content. This includes text, images or links featuring nudity, sex, hard violence or other graphically disturbing content.'},
{name: '4.', value: 'if you see something against the rules or something that makes you feel unsafe, let staff know. We want this server to be a welcoming space!'},
{name: '5.', value: 'Keep public conversations in English.'},
{name: '6.', value: 'This list is not exhaustive and will be updated as we see fit.'}
)
.setImage('./images/rules.png')
.setFooter('Make sure to follow the rules');
message.channel.send(newEmbed);
}
}
主文件:
// grabs the discord.js bot file for import //
const {Client, Intents, Collection} = require('discord.js');
// create the client for the bot //
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// prefix to use for bot commands //
const prefix = '!';
const fs = require('fs');
const Discord = require('./commands/discord');
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
// log to console that the bot has successfully logged in //
client.once('ready', () => {
console.log("Reformed Esports is online");
});
/* Command handler, checking if message starts with prefix and is not the bot,
allowing commands to have multiple words */
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
} else if(command === 'discord'){
client.commands.get('discord').execute(message, args);
} else if(command === 'pugs') {
client.commands.get('pugs').execute(message, args);
} else if(command === 'command'){
client.commands.get('command').execute(message, args, Discord)
}
});
// bot login using discord bot token //
client.login('blank');
完整错误图片:
您发送的似乎是 ./commands/discord
作为参数而不是真正的 discord.js 包裹。我会将 Embed
添加到 const {Client, Intents, Collection} = require('discord.js');
,并在 client.commands.get('command').execute(message, args, Discord)
.
中发送 Embed
而不是 Discord
您应该传递 discord.js 模块,但您传递了一个文件。这可能与 discord.js 模块具有不同的功能、属性等。
此代码将修复错误:
client.commands.get('command').execute(message, args, require('discord.js'))
此外,现在必须使用 embeds
属性
发送嵌入
message.channel.send({ embeds: [newEmbed] })
我最近尝试为我的 discord 机器人添加 MessageEmbed,但出现此错误:
TypeError: Discord.MessageEmbed is not a constructor
我想知道是否有人知道如何解决这个问题,我已经尝试了一些我可以在网上找到的 rip,一些包括尝试重新安装 node.js 和 discord.js,其他提到不同的方法,比如使用 NewMessageEmbed(),但是 none 一直在为我工作,如果有人比我更有经验可以提供解决方案,我会提供所有涉及的代码和屏幕截图错误,提前致谢。
命令文件:
module.exports = {
name: 'command',
description: "Embeds!",
execute(message, args, Discord){
const newEmbed = new Discord.MessageEmbed()
.setColor('#FFA62B')
.setTitle('Rules')
.setURL('https://discord.gg/fPAsvEey2k')
.setDescription('**This is an embed for the server rules.**')
.addFields(
{name: '1.', value: 'Treat everyone with respect. Absolutely no harassment, witch hunting, sexism, racism or hate speech will be tolerated.'},
{name: '2.', value: 'No spam or self-promotion (server invites, advertisements, etc.) without permission from a staff member. This includes DMing fellow members.'},
{name: '3.', value: 'No NSFW or obscene content. This includes text, images or links featuring nudity, sex, hard violence or other graphically disturbing content.'},
{name: '4.', value: 'if you see something against the rules or something that makes you feel unsafe, let staff know. We want this server to be a welcoming space!'},
{name: '5.', value: 'Keep public conversations in English.'},
{name: '6.', value: 'This list is not exhaustive and will be updated as we see fit.'}
)
.setImage('./images/rules.png')
.setFooter('Make sure to follow the rules');
message.channel.send(newEmbed);
}
}
主文件:
// grabs the discord.js bot file for import //
const {Client, Intents, Collection} = require('discord.js');
// create the client for the bot //
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// prefix to use for bot commands //
const prefix = '!';
const fs = require('fs');
const Discord = require('./commands/discord');
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
// log to console that the bot has successfully logged in //
client.once('ready', () => {
console.log("Reformed Esports is online");
});
/* Command handler, checking if message starts with prefix and is not the bot,
allowing commands to have multiple words */
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
} else if(command === 'discord'){
client.commands.get('discord').execute(message, args);
} else if(command === 'pugs') {
client.commands.get('pugs').execute(message, args);
} else if(command === 'command'){
client.commands.get('command').execute(message, args, Discord)
}
});
// bot login using discord bot token //
client.login('blank');
完整错误图片:
您发送的似乎是 ./commands/discord
作为参数而不是真正的 discord.js 包裹。我会将 Embed
添加到 const {Client, Intents, Collection} = require('discord.js');
,并在 client.commands.get('command').execute(message, args, Discord)
.
Embed
而不是 Discord
您应该传递 discord.js 模块,但您传递了一个文件。这可能与 discord.js 模块具有不同的功能、属性等。
此代码将修复错误:
client.commands.get('command').execute(message, args, require('discord.js'))
此外,现在必须使用 embeds
属性
message.channel.send({ embeds: [newEmbed] })