Embed: DiscordAPIError: Cannot send an empty message

Viewed 9329

It's me again..

Alright so:

I'm trying to make a command that will warn users they joined a wrong server, But when I run the command, I get the Cannot send an empty msg error..

Really, any help would be appreciated!

const Discord = require("discord.js")

module.exports.run = async (client, message, args, err) => { 
const embed = new Discord.MessageEmbed().setTitle('Hey!').setDescription('We think you have our server mistaken. etc etc')
     if (!args[0]) return message.reply('Who?', { allowedMentions: { repliedUser: false } });
     const member = message.mentions.members.first() || await message.guild.members.fetch(args[0]).catch(e => {
      check = true;
      return message.reply('Can\'t find specefied member! Provide a valid ID, or mention ig lol.', { allowedMentions: { repliedUser: false } });
    });
    message.channel.send(embed).catch(err)
    message.channel.send(`${member}`)
    }

Error:

DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (C:\Users\stupk\Desktop\Holo\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (C:\Users\stupk\Desktop\Holo\node_modules\discord.js\src\rest\RequestHandler.js:50:14) {
  method: 'post',
  path: '/channels/843567563648139317/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
    },
    files: []
  }
}
2 Answers

Now that discord.js has updated to v13, the accepted answer is slightly outdated. The API now supports up to 10 embeds per message.

So, instead of:

message.channel.send({ embed: embed })

Use:

message.channel.send({ embeds: [embed1, embed2, embed3... embed10] })

You can, of course, just insert a single embed as well:

message.channel.send({ embeds: [embed] })

Changelog: https://discordjs.guide/additional-info/changes-in-v13.html#sending-messages-embeds-files-etc

You might find some extra stuff in there as well.

let me try to help! Lots of users recently encountered the same error!

Instead of:

message.channel.send(embed)

do:

message.channel.send({ embed: embed });
Related