Search code examples
javascriptnode.jsdiscorddiscord.js

I get error while making a status command in discord.js


I was making a status command for my discord bot, that returns title, description, and some fields.

I ran into an error. I am using discord.js v13 and Node.js v16.14.2.

My code:

const { MessageEmbed, CommandInteraction, Client, version } = require("discord.js");
const { connection } = require("mongoose");
const os = require("os");
const quick = require('quick.db');

module.exports = {
    name: "status",
    asliases: [],
    permissions: [],
    description: "Displays the status of the client",

    async execute(message, args, cmd, client, Discord, profileData) {
        const messagePing = Date.now();
        const endMessagePing = Date.now() - messagePing;
        const status = [
            "Disconnected",
            "Connected",
            "Connecting",
            "Disconnecting"
        ];
        const embed = new MessageEmbed()
            .setColor("RANDOM")
            .setTitle(`🌟 PDM Bot Status`)
            .setThumbnail('https://imgur.com/IDhLmjc')
            .setDescription("in the Skys with PDM Bot")
            .addFields(
                { name: "🧠 Client", value: client.tag, inline: true },
                { name: "📆 Created", value: `<t:${parseInt(client.createdTimestamp / 1000, 10)}:R>`, inline: true },
                { name: "✅ Verified", value: "No, Please help us to get Verified :)", inline: true },
                { name: "👩🏻‍💻 Owner", value: 'Pooyan#9627', inline: true },
                { name: "📚 Database", value: 'Connected', inline: true },
                { name: "⏰ Up Since", value: `<t:${parseInt(client.readyTimestamp / 1000, 10)}:R>`, inline: true },
                { name: "🏓 Ping", value: `${endMessagePing}ms , for more information, use -ping command`, inline: true },
                { name: "📃 Commands", value: `45`, inline: true },
                { name: "🏨 Servers", value: `${client.guilds.cache.size}`, inline: true },
                { name: "👦 Users", value: `${client.guilds.cache.memberCont}`, inline: true },
            );
        message.channel.send({ embeds: [embed], ephemeral: true });
    }
}

The error that I ran into because of the embed:

RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
    at Function.verifyString (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\util\Util.js:416:41)
    at Function.normalizeField (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\structures\MessageEmbed.js:544:19)
    at C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\structures\MessageEmbed.js:565:14
    at Array.map (<anonymous>)
    at Function.normalizeFields (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\structures\MessageEmbed.js:564:8)
    at MessageEmbed.addFields (C:\Users\Pooyan\Desktop\PDM Bot Main\node_modules\discord.js\src\structures\MessageEmbed.js:328:42)
    at Object.execute (C:\Users\Pooyan\Desktop\PDM Bot Main\commands\status.js:26:14)
    at module.exports (C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:104:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  [Symbol(code)]: 'EMBED_FIELD_VALUE'
}

I read one or two similar questions/posts but it did not help.


Solution

  • Multiple properties here don't exist, including:

    • client.tag
    • client.createdTimestamp
    • client.guilds.cache.memberCount

    Here are the things you should replace them with:

    // client.tag
    client.user.tag
    // client.createdTimestamp
    client.user.createdTimestamp
    // client.guilds.cache.memberCount
    client.guilds.cache.reduce((acc, g) => acc + g.memberCount, 0)