Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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: }).

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: ,
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading