Home > database >  Discord Bot Embed returning "Cannot send empty message"
Discord Bot Embed returning "Cannot send empty message"

Time:03-19

I've been reworking my help command, which includes making a new Discord Embed but whenever I try to run the command, it crashes to console with

DiscordAPIError: Cannot send an empty message

I've tried remaking the embed (using this tool as all its embed were made using this) and looking over it multiple times with nothing at least obvious to me that would cause the error.

My code:

module.exports = {
    
    name: 'help',
    description: 'Get help on anything from commands, to what the bot does! just not your homework..',
  syntax: '<Command>',

    execute(client, message, args) {
    const footerTxt = require('../config.json')
       const Embed = {
        "title": "HELP SEYMOUR! THE BOT IS ON FIRE!",
        "description": "Get help on anything from commands, to what the bot does! just not your homework..",
        "color": 9442302,
        "footer": {
          "icon_url": message.author.displayAvatarURL,
          "text": footerTxt   " | No mother it's just the northern lights"
        },
        "fields": [
          {
            "name": "Arguments",
            "value": "<> is optionable,\n[ ] is required. \n ```<Command>```"
          },
          {
            "name": "...Or is the bot actually on fire?",
            "value": "<> is optionable,\n[ ] is required. \n ```<Command>```"
          }
        ]
      };
      message.channel.send({ Embed });
}};

It is using Discord.JS v12

CodePudding user response:

To send embeds when you construct them with an object all you have to do is: message.channel.send({ embed: Embed }), so your final code would be:

module.exports = {
    
    name: 'help',
    description: 'Get help on anything from commands, to what the bot does! just not your homework..',
  syntax: '<Command>',

    execute(client, message, args) {
    const footerTxt = require('../config.json')
       const Embed = {
        "title": "HELP SEYMOUR! THE BOT IS ON FIRE!",
        "description": "Get help on anything from commands, to what the bot does! just not your homework..",
        "color": 9442302,
        "footer": {
          "icon_url": message.author.displayAvatarURL,
          "text": footerTxt   " | No mother it's just the northern lights"
        },
        "fields": [
          {
            "name": "Arguments",
            "value": "<> is optionable,\n[ ] is required. \n ```<Command>```"
          },
          {
            "name": "...Or is the bot actually on fire?",
            "value": "<> is optionable,\n[ ] is required. \n ```<Command>```"
          }
        ]
      };
      message.channel.send({ embed: Embed });
}};

You can learn more about embeds in discord.js v12 in here => discord.js | v12

CodePudding user response:

As per usual, it's always the little things one can tend to overlook. The issue was being caused by missing parentheses in the message.author.displayAvatarURL

Making the final code be:

    
    name: 'help',
    description: 'Get help on anything from commands, to what the bot does! just not your homework..',
  syntax: '<Command>',

    execute(client, message, args) {
    const {footerTxt} = require('../config.json');
       const Embed = {
        "title": "HELP SEYMOUR! THE BOT IS ON FIRE!",
        "description": "Get help on anything from commands, to what the bot does! just not your homework..",
        "color": 9442302,
        "footer": {
          "icon_url": message.author.displayAvatarURL,
          "text": footerTxt   " | No mother it's just the northern lights"
        },
        "fields": [
          {
            "name": "Arguments",
            "value": "<> is optionable,\n[ ] is required. \n ```<Command>```"
          },
          {
            "name": "...Or is the bot actually on fire?",
            "value": "Join the [support server!]( )"
          }
        ]
      };
      message.channel.send({ Embed });
}};

CodePudding user response:

"text": footerTxt   " | No mother it's just the northern lights"

make it into

"text": `${footerTxt}`   " | No mother it's just the northern lights"

Might work the code

  • Related