I get error :embed.description is not a function - discord.js

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()

Related

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

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.

How can I make my embed fields like this in discord.js v13?

Embed
Can someone explain how I can make my embeds like that in discord.js v13?
You can use a markdown on embed and some logic to create this wonderful embed.
const embed = new MessageEmbed()
.setTitle("SERVER INFO")
.addFields(
{name: "```Field1```", value: "```Something field1```", inline: true},
{name: "```Field2```", value: "```Something field2```", inline: true},
)
.addField("```Field3```", "```Something field3```")
.addFields(
{name: "```Field1```", value: "```Something field1```", inline: true},
{name: "```Field2```", value: "```Something field2```", inline: true},
)
.setColor('RANDOM')
.setTimestamp()
message.channel.send({embeds: [embed]})
For another purpose, calling a const & let & var, you can use backslash + backquote.
const user = message.author.username;
const user1 = message.author.id;
const user2 = message.author.tag;
const embed = new MessageEmbed()
.setTitle("SERVER INFO")
.addFields(
{name: "Field1", value: `\`\`\`${user}\`\`\``, inline: true},
{name: "Field2", value: `\`\`\`${user1}\`\`\``, inline: true},
)
.addField("Field3", `\`\`\`${user2}\`\`\``)
.addFields(
{name: "Field4", value: `\`\`\`${user}\`\`\``, inline: true},
{name: "Field5", value: `\`\`\`${user1}\`\`\``, inline: true},
)
.addField("Field6", `\`\`\`${user2}\`\`\``)
.setColor('RANDOM')
.setTimestamp()
message.channel.send({embeds: [embed]})

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)

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