Home > Net >  Message content must be a non-empty string when editing message
Message content must be a non-empty string when editing message

Time:03-28

I wanted to make a command to make the bot return its connection status to the database, but I got an error and I am a little confused now.

RangeError [MESSAGE_CONTENT_TYPE]: Message content must be a non-empty string.
const { MessageEmbed } = require('discord.js');
const quick = require('quick.db');

module.exports = {
  name: 'ping',
  aliases: [],
  description: 'Get bot ping.',
  permissions: [],
  async execute(message, client) {
    const ping = await getDBPingData();
    const messagePing = Date.now();
    const msg = await message.channel.send('Loading...');
    const endMessagePing = Date.now() - messagePing;

    const embed = new MessageEmbed()
      .setDescription(
        `
        Database ping data:
        - Fetch ping: \`${ping.endGet}ms\`
        - Wright ping: \`${ping.endWright}ms\`
        - Avrage ping: \`${ping.avarage}ms\`
        Message ping: \`${endMessagePing}ms\`
      `
      )
      .setColor('GREEN')
      .setTimestamp();

    msg.edit({
      content: '',
      embed,
    });
  },
};

async function getDBPingData() {
  // get the fetch data ping
  const startGet = Date.now();
  await quick.get('QR=.');
  const endGet = Date.now() - startGet;

  // get the wright data ping
  const startWright = Date.now();
  await quick.set('QR=.', Buffer.from(startWright.toString()).toString('base64'));
  const endWright = Date.now() - startWright;

  // avrage ping time
  const avarage = (endGet   endWright) / 2;
  try {
    quick.delete('QR=.'); 
  } catch (error) {}
  return { endGet, endWright, avarage };
}

I am using discord.js v13, and the packages in use for this command are: discord.js and quick.db.

CodePudding user response:

In v13, 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, so your message edit should be msg.edit({ embeds: [embed] }).

If you also want to remove the previous text (Loading...), you need to add content: null as providing an empty string ('') as the content will throw a RangeError.

msg.edit({
  content: null,
  embeds: [embed],
});

CodePudding user response:

Try this:

    // only need to edit embed in an embeds array
    msg.edit({ embeds: [embed] })
  • Related