Discord.JS v11.2.1创建MessageEmbed报错TypeError求助
Hey there, let's break down why you're hitting this error and how to fix it quickly.
The Root Cause
The error happens because Discord.js v11.x requires a message object as the first parameter when creating a MessageEmbed—but most modern tutorials you're seeing are for v12+ of the library, which removed this requirement.
Looking at the line from MessageEmbed.js you mentioned:
Object.defineProperty(this, 'client', { value: message.client });
The constructor is trying to access message.client, but if you didn't pass a message object to new MessageEmbed(), it's undefined—hence the error.
How to Fix It
You have two options depending on whether you want to stick with v11 or upgrade:
Option 1: Stick with Discord.js v11.2.1
When creating your embed, pass the message object (from your client.on('message') callback) as the first argument:
// Inside your message event handler client.on('message', message => { // Option A: Pass message + embed data directly const embed = new Discord.MessageEmbed(message, { title: "Hello!", description: "This is a working embed for v11", color: 0x00ff00 }); // Option B: Initialize with message, then set properties const embed = new Discord.MessageEmbed(message); embed.setTitle("Hello!") .setDescription("This also works") .setColor(0x00ff00); // Send the embed message.channel.send(embed); });
Option 2: Upgrade to a Newer Discord.js Version
If you prefer the cleaner syntax from newer tutorials (no message parameter), you can upgrade Discord.js—but note that v12+ requires Node.js 12.0.0 or higher (you're on 8.9.4 right now).
First upgrade Node.js to a supported version, then update Discord.js:
npm install discord.js@latest
Then your embed code can follow the modern pattern:
const embed = new Discord.MessageEmbed() .setTitle("Hello!") .setDescription("No message parameter needed here");
Quick Check
Double-check that you're calling new MessageEmbed() inside your message event handler, where the message object is available. If you're trying to create an embed outside that scope, you'll need to pass a valid message object or consider upgrading.
内容的提问来源于stack exchange,提问作者Henry Morales

