Discord.js Embed Builder Error (.description field required) - discord.js

When trying to send a Discord.js embed, I'm getting a "DiscordAPIError: Invalid Form Body
embeds[0].description: This field is required" error. Does anyone know why this is happening? I suspect this might be an issue with the source code. I'm using Discord.js v13, and I copied the embed straight off of the Discord.js guide website:
const exampleEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor({ name: 'Some name', iconURL: 'https://i.imgur.com/AfFp7pu.png', url: 'https://discord.js.org' })
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/AfFp7pu.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addFields({ name: 'Inline field title', value: 'Some value here', inline: true })
.setImage('https://i.imgur.com/AfFp7pu.png')
.setTimestamp()
.setFooter({ text: 'Some footer text here', iconURL: 'https://i.imgur.com/AfFp7pu.png' });
outputChannel.send({ embeds: [exampleEmbed] });
Thanks!

You can't use EmbedBuilder in discord.js v13 because this is a discord.js v14 constructor. Just change it to MessageEmbed and it should work.

Related

A Discord Bot Embed Error: DiscordAPIError: Cannot send an empty message

I've tried writing a discord bot, nearly finished it but this error just appeared and I don't know what's wrong with the code.
The Error:
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (C:\Users\user\OneDrive\Desktop\discordbot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\user\OneDrive\Desktop\discordbot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async TextChannel.send (C:\Users\user\OneDrive\Desktop\discordbot\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:176:15) {
method: 'post',
path: '/channels/991019562625552466/messages',
code: 50006,
httpStatus: 400,
requestData: {
json: {
content: undefined,
tts: false,
nonce: undefined,
embeds: undefined,
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined
},
files: []
}
}
The code:
module.exports = {
name: 'command',
description: "Embeds!",
execute(message, args, Discord) {
const newEmbed = new Discord.MessageEmbed()
.setColor('#FF0000')
.setTitle('This is a title.')
.setURL('https://www.youtube.com')
.setDescription('This is an embed.')
.addFields(
{name: 'Field 1', value: 'Text 1'},
{name: 'Field 2', value: 'Text 2'},
{name: 'Field 3', value: 'Text 3'}
)
.setImage('https://upload.wikimedia.org/wikipedia/commons/9/9a/Gull_portrait_ca_usa.jpg')
message.channel.send(newEmbed);
}
}
What's the problem?
As of discord.js v13 embeds are sent via the MessageOptions object passed to the send method.
Updated code would be:
message.channel.send({embeds: [newEmbed]});
Documentation:
BaseGuildTextChannel#send takes
<MessageOptions> extends <BaseMessageOptions>

How do you fix the discord.js guide embed code error?

I am trying to create an embed and I pasted the code straight from the discord.js guide right into the code but it's not working and I can't figure out why it's wrong. The code and error are below
module.exports = {
name: 'infotest',
description: 'infotest',
execute(message, args) {
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
channel.send(exampleEmbed);
},
};
ReferenceError: Discord is not defined
at Object.execute (/home/runner/BotNameHere/Commands/info2.js:5:24)
at Client.<anonymous> (/home/runner/BotNameHere/index.js:33:32)
at Client.emit (events.js:314:20)
at Client.EventEmitter.emit (domain.js:483:12)
at MessageCreateAction.handle (/home/runner/BotNameHere/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/home/runner/BotNameHere/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/home/runner/BotNameHere/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/home/runner/BotNameHere/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/home/runner/BotNameHere/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/home/runner/BotNameHere/node_modules/ws/lib/event-target.js:132:16)
Read your error, you have to define the variable Discord. Just use require() to use the discord.js module.

My Discord bot wont show the embed and has no errors what do i do?

When I code the embed, it doesn't work
module.exports = {
name: 'ping',
description: 'it shows the servers ping',
execute(message, args, Discord) {
const newEmbed = new Discord.MessageEmbed()
.setColor('#00A6FF')
.setTitle('Ping')
.setURL('https://discord.gg/X9cpCJ8F5J')
.setDescription('Test')
.setFooter('Test');
message.channel.send(newEmbed);
}
}
No errors, doesn't send the embed doesn't even send a message, no message and no errors
If you use discord.js:
You can use this code instead (official manual of discord.js):
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
channel.send(exampleEmbed);
If you use discord.py:
You can use this code instead (I tested with my bot also):
if message.content.startswith("!command"):
embed=discord.Embed(title="ping", description="Test", color=0x00A6FF)
embed.set_author(name="Test", url="https://discord.gg/X9cpCJ8F5J", icon_url="https://cdn.discordapp.com/attachments/541913766296813570/672624076589760512/DRG.png")
embed.set_footer(text="Test")
await message.channel.send(embed=embed)

I get error :embed.description is not a function

I get error embed.description is not a function and I dont know why
I try to do command that write a random command
name: 'random game',
description: "All commands",
execute(message, args, Discord){
const embed = new Discord.MessageEmbed()
let Games = [
"Fortnite",
"Overwatch",
"Among us",
"Rocket league",
"Fall guys",
"Spellbreak",
"Counter Strike Global Offensive",
"Minecraft",
"Valorant",
]
embed.setTitle("Random Game");
embed.description(`You should play ${(Games[Math.floor(Math.random() * (Games.length))])}`);
embed.setColor("RANDOM");
return message.channel.send(embed)
}
}
If you need embed help, the Discord.JS docs can be very helpful.
Here is a sample embed that uses every method in the #messageEmbed() obj:
// at the top of your file
const Discord = require('discord.js');
// inside a command, event listener, etc.
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields(
{ name: 'Regular field title', value: 'Some value here' },
{ name: '\u200B', value: '\u200B' },
{ name: 'Inline field title', value: 'Some value here', inline: true },
{ name: 'Inline field title', value: 'Some value here', inline: true },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
channel.send(exampleEmbed);
Also, your error (as mentioned above) is that it is #setDescription()

Trouble with discord bot embeds

First I'd like to point out that I just started learning discord.js a month ago, so my code is probably all wrong and I understand that.
I'm trying to learn how to write embeds, but a whole ton of stuff doesn't work, mainly because I don't know where to put everything.
In my main js file, I have the following:
} else if (command == 'embed') {
client.commands.get('embed').execute(message, args);
}
And in my embed.js file, I have all of this code which doesn't work at all.
module.exports = {
name: 'embed',
description: 'example embed.',
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields({
name: 'Regular field title',
value: 'Some value here'
}, {
name: '\u200B',
value: '\u200B'
}, {
name: 'Inline field title',
value: 'Some value here',
inline: true
}, {
name: 'Inline field title',
value: 'Some value here',
inline: true
}, )
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
channel.send(exampleEmbed);
}
Thank you for listening to this. I'd love for anyone to help.
You are trying to export a MessageEmbed in the module.exports, but you need to export a function called execute.
module.exports = {
name: 'embed',
description: 'example embed.',
execute: (message, args) => {
const exampleEmbed = new Discord.MessageEmbed()
.setColor('#0099ff')
.setTitle('Some title')
.setURL('https://discord.js.org/')
.setAuthor('Some name', 'https://i.imgur.com/wSTFkRM.png', 'https://discord.js.org')
.setDescription('Some description here')
.setThumbnail('https://i.imgur.com/wSTFkRM.png')
.addFields({
name: 'Regular field title',
value: 'Some value here'
}, {
name: '\u200B',
value: '\u200B'
}, {
name: 'Inline field title',
value: 'Some value here',
inline: true
}, {
name: 'Inline field title',
value: 'Some value here',
inline: true
}, )
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/wSTFkRM.png')
.setTimestamp()
.setFooter('Some footer text here', 'https://i.imgur.com/wSTFkRM.png');
message.channel.send(exampleEmbed);
}
}

Resources