Search code examples
javascriptnode.jsdiscord.js

I have this error when i execute my lyrics command : DiscordAPIError: Cannot send an empty message


Hi can someone help me I have this error when I run my command lyrics: DiscordAPIError: Cannot send an empty message (it's a music bot that uses a command handler)

const { MessageEmbed } = require("discord.js");
const lyricsFinder = require("lyrics-finder");

module.exports = {
      name: "lyrics",
    aliases: ['ly'],
    category: "Music",
    description: "View the lyrics of a song",
    args: false,
    usage: "",
    permission: [],
    owner: false,
    player: true,
    inVoiceChannel: true,
    sameVoiceChannel: true,
execute: async (message, args, client, prefix) => {
  
  const player = message.client.manager.get(message.guild.id);
  
  if (!player.queue.current) {
    let thing = new MessageEmbed()
        .setColor("RED")
        .setDescription("There is no music playing.");
    return message.channel.send(thing);
  }

    let lyrics = null;
    const title = player.queue.current
    try {
      lyrics = await lyricsFinder(player.queue.current.title, "");
      if (!lyrics) lyrics = `No lyrics found for ${title}.`, { title: title }
    } catch (error) {
      lyrics = `No lyrics found for ${title}.`, { title: title }
    }

    let lyricsEmbed = new MessageEmbed()
      .setTitle(`${title} - Lyrics`, { title: title })
      .setDescription(`${lyrics}`)
      .setColor("#F8AA2A")
      .setTimestamp();

      if (lyricsEmbed.description.length >= 2048)
      lyricsEmbed.description = `${lyricsEmbed.description.substr(0, 2045)}...`;
      return message.channel.send(lyricsEmbed).catch(console.error);
        
  }
};

Solution

  • Updating to v13 will cause a lot of errors because of breaking changes!
    You can find them all listed in the guide right here.
    But in your case, it was about how Discord.js handles parameters with the channel.send().

     - channel.send(embed);
     + channel.send({ embeds: [embed, embed2] });
    
     - channel.send('Hello!', { embed });
     + channel.send({ content: 'Hello!', embeds: [embed, embed2] });