Home > Enterprise >  Cannot send an empty message form like {embeds:[embed]}
Cannot send an empty message form like {embeds:[embed]}

Time:10-14

I wrote a new command when my bot ran on my pc and not a server. While the bot ran on my pc the command worked very well, but after I put my bot into a server the command stopped working and I always get an error message: DiscordAPIError: Cannot send an empty message

The code:

const Discord = require("discord.js");
const recon = require('reconlx');
const rpages = recon.ReactionPages
const moment = require('moment');
const fs = require('fs');
module.exports = class HelpCommand extends BaseCommand {
    constructor() {
        super('help', 'moderation', []);
    }

    async run(client, message, args) {
        const y = moment().format('YYYY-MM-DD HH:mm:ss')
        const sayEmbed1 = new Discord.MessageEmbed()
            .setTitle(`example`)
        const sayEmbed2 = new Discord.MessageEmbed()
            .setTitle(`example`)
        const sayEmbed3 = new Discord.MessageEmbed()
            .setTitle(`example`)
        const sayEmbed5 = new Discord.MessageEmbed()
            .setTitle(`example`)
        const sayEmbed4 = new Discord.MessageEmbed()
            .setTitle(`example`)
        const sayEmbed6 = new Discord.MessageEmbed()
            .setTitle(`example`)
            .setDescription("[A készítőm Weboldala](https://istvannemeth1245.wixsite.com/inde/)\n\n")

        try {
            await
                message.delete();
            const pages = [{ embed: sayEmbed1 }, { embed: sayEmbed2 }, { embed: sayEmbed3 }, { embed: sayEmbed4 }, { embed: sayEmbed5 }, { embed: sayEmbed6 }];
            const emojis = ['◀️', '▶️'];
            const textPageChange = true;
            rpages(message, pages, textPageChange, emojis);

        } catch (err) {
            console.log(err);
            message.channel.send('Nem tudom ki írni az üzenetet');
        }
        const contetn = `\n[${y}] - ${message.author.username} használta a help parancsot. `;
        fs.appendFile('log.txt', contetn, err => {
            if (err) {
                console.err;
                return;
            }
        })
    }
}

Full error message:

throw new DiscordAPIError(request.path, data, request.method, res.status);
^
DiscordAPIError: Cannot send an empty message
at RequestHandler.execute (/home/container/Lee-Goldway/node_modules/discord.js/src/rest/RequestHandler.js:154:13)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RequestHandler.push (/home/container/Lee-Goldway/node_modules/discord.js/src/rest/RequestHandler.js:39:14) {
method: 'post',
path: '/channels/833629858210250813/messages',
code: 50006,
httpStatus: 400
}

CodePudding user response:

In the code provided, there appears to be no code that references "{embeds:[embed]}".
However, assuming the error is coming from this line:

message.channel.send('Nem tudom ki írni az üzenetet');

Referring to the official documentation, you can provide an object.

For example:

message.channel.send({ content: 'Nem tudom ki írni az üzenetet' });

CodePudding user response:

A couple of things. Are you sure that this reconlx package is compatible with your discord.js version? It's always a good idea to post your discord.js version when you have a problem with libraries.

If you're using reconlx v1, you can see in their old documentation that in ReactionPages the second parameter takes an array of embeds. If you check the source code, you can see that it tries to send the first item of pages as an embed, like this: message.channel.send({ embeds: [pages[0]] }).

It means that with your code embeds is an array where the first item is an object that has an embed key with the sayEmbed1 embed, while discord.js accepts an array of MessageEmbeds.

I would try to pass down an array of embeds like this:

const pages = [
  sayEmbed1,
  sayEmbed2,
  sayEmbed3,
  sayEmbed4,
  sayEmbed5,
  sayEmbed6,
];

PS: ki írni is incorrect. When the verb particle precedes the verb, they are written as one word. So, it should be kiírni. :)

  • Related