Home > Software engineering >  When trying to send a embed it just throughs an error
When trying to send a embed it just throughs an error

Time:10-05

Im trying to make a embed and it keeps showing this error

DiscordAPIError: Cannot send an empty message

Heres my code:

        const infoembed = new MessageEmbed()
            .setColor('#0099ff')
            .setTitle(responce.asset.title)
            
        umsg.channel.send({ embeds: infoembed });

CodePudding user response:

All messages sent by bots now support up to 10 embeds. As a result, the embed option was removed and replaced with an embeds array, which must be in the options object.

        umsg.channel.send({ embeds: [infoembed] });

read docs

CodePudding user response:

If responce.asset.title is empty - you will get an error because discord can't send embed with empty title! But you can try using this code:

const infoembed = new MessageEmbed()
      .setColor('#0099ff')
      .setTitle(`** **`);

message.channel.send(infoembed)

CodePudding user response:

If you're on discord.js v13 you have to put your embed in an array:

const infoembed = new MessageEmbed()
            .setColor('#0099ff')
            .setTitle(responce.asset.title)
            
umsg.channel.send({ embeds: [infoembed] });

And if you want to add some text content to the message you simply have to add the field content:

const infoembed = new MessageEmbed()
            .setColor('#0099ff')
            .setTitle(responce.asset.title)
            
umsg.channel.send({ content: 'Hello world!', embeds: [infoembed] });

Since you're using discord.js v12, you have to remove the curly brackets and the embeds field:

const infoembed = new MessageEmbed()
            .setColor('#0099ff')
            .setTitle(responce.asset.title)
            
umsg.channel.send(infoembed);
  • Related