所以我最近試圖為我的不和諧機器人添加一個 MessageEmbed,但我收到了這個錯誤:
型別錯誤:Discord.MessageEmbed 不是建構式
我想知道是否有人知道如何解決這個問題,我已經嘗試了一些我可以在網上找到的 rip,其中一些包括嘗試重新安裝 node.js 和 discord.js,其他提到了一種不同的方法,例如使用 NewMessageEmbed() 代替,但是他們都沒有為我作業過,如果有比我多一點經驗的人可以提供解決方案,那就太好了,我已經提供了所有涉及的代碼和錯誤的螢屏截圖,提前致謝:)
命令檔案:
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 succesfully 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');
完整錯誤的影像:

uj5u.com熱心網友回復:
您應該傳遞 discord.js 模塊,而是傳遞一個檔案。這可能與 discord.js 模塊具有不同的功能、屬性等。
此代碼將修復錯誤:
client.commands.get('command').execute(message, args, require('discord.js'))
此外,現在必須使用embeds屬性發送嵌入
message.channel.send({ embeds: [newEmbed] })
uj5u.com熱心網友回復:
看起來您是./commands/discord作為引數而不是真正的 discord.js 包發送的。我會添加Embed到const {Client, Intents, Collection} = require('discord.js');, 并發送Embed而不是Discord在client.commands.get('command').execute(message, args, Discord).
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/314011.html
標籤:javascript 节点.js 视觉工作室代码 不和谐.js 类型错误
