1
votes

so I'm trying to make a help command with list of commands showed in embed. My code kinda works but it throws an error "DiscordAPIError: Cannot send an empty message" and I've tried already everything I know and what I've found but I can't fix it.

Here's the code

const Discord = require('discord.js');
const { prefix } = require('../config.json');

module.exports = {
  name: 'help',
  description: 'List all of my commands or info about a specific command.',
  aliases: ['commands', 'cmds'],
  usage: '[command name]',
  cooldown: 5,
  execute(msg, args) {

    const data = [];
    const { commands } = msg.client;

    if (!args.length) {

        const helpEmbed = new Discord.MessageEmbed()
            .setColor('YELLOW')
            .setTitle('Here\'s a list of all my commands:')
            .setDescription(commands.map(cmd => cmd.name).join('\n'))
            .setTimestamp()
            .setFooter(`You can send \`${prefix}help [command name]\` to get info on a specific command!`);

        msg.author.send(helpEmbed);

        return msg.author.send(data, { split: true })
            .then(() => {
                if (msg.channel.type === 'dm') return;
                msg.reply('I\'ve sent you a DM with all my commands!');
            })
            .catch(error => {
                console.error(`Could not send help DM to ${msg.author.tag}.\n`, error);
                msg.reply('it seems like I can\'t DM you! Do you have DMs disabled?');
            });
    }

    const name = args[0].toLowerCase();
    const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name));

    if (!command) {
        return msg.reply('that\'s not a valid command!');
    }

    data.push(`**Name:** ${command.name}`);

    if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`);
    if (command.description) data.push(`**Description:** ${command.description}`);
    if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`);

    data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`);

    msg.channel.send(data, { split: true });
 },
};
2

2 Answers

0
votes

You should try replace this line : msg.channel.send(data, { split: true });

with msg.channel.send(data.join(' '), { split: true }); since your data variable is an array and not a string

0
votes

The problem is as the error states. You are trying to send an empty message somewhere.

You can try replacing msg.channel.send(data) with msg.channel.send(data.join('\n')), since the data variable is an array.

I don't see why sending an array doesn't work though.