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>
Related
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.
I'm getting this error everytime i clicked the button i made in v14, i followed how the v14 buttons made and work but i don't know why this error is showing and my buttons isn't working.
Err:
DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required
at SequentialHandler.runRequest (/home/runner/skyanime-utilities/node_modules/#discordjs/rest/dist/index.js:748:15)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.queueRequest (/home/runner/skyanime-utilities/node_modules/#discordjs/rest/dist/index.js:560:14)
at async REST.request (/home/runner/skyanime-utilities/node_modules/#discordjs/rest/dist/index.js:1000:22)
at async GuildChannelManager.create (/home/runner/skyanime-utilities/node_modules/discord.js/src/managers/GuildChannelManager.js:145:18)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:393:10) {
rawError: {
code: 50035,
errors: {
name: {
_errors: [
{
code: 'BASE_TYPE_REQUIRED',
message: 'This field is required'
}
]
}
},
message: 'Invalid Form Body'
},
code: 50035,
status: 400,
method: 'POST',
url: 'https://discord.com/api/v10/guilds/1000655001888235540/channels',
requestBody: {
files: undefined,
json: {
name: undefined,
topic: undefined,
type: undefined,
nsfw: undefined,
bitrate: undefined,
user_limit: undefined,
parent_id: undefined,
position: undefined,
permission_overwrites: undefined,
rate_limit_per_user: undefined,
rtc_region: undefined,
video_quality_mode: undefined
}
}
}
here's the handler of the buttons im working
https://sourceb.in/FepPx2RpCK
here is my interaction handler https://sourceb.in/h5zEL0I3oF
and the command where buttons and id https://sourceb.in/RstCfscZpY
The issue happens during channel creation. The first argument (channel name) has been moved to the name property.
Change
await guild.channels.create(`${customId + "-" + ID}`, {
type: ChannelType.GuildText,
parent: parent_ID,
permissionOverwrites: [
{
id: member.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
},
{
id: everyone_ID,
deny: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
},
],
})
To
await guild.channels.create({
name: `${customId + "-" + ID}`,
type: ChannelType.GuildText,
parent: parent_ID,
permissionOverwrites: [
{
id: member.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
},
{
id: everyone_ID,
deny: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
},
],
})
Make sure to send your command.data as JSON.
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
//convert the data to JSON as below
commands.push(command.data.toJSON());
}
{
body: commands
}
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.
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 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()