Search code examples
javascriptnode.jsdiscorddiscord.js

Expected the value to be an object, but received string instead


I’ve recently updated to v14 of discordjs (I think), and I’ve been getting tons of errors as this being one of many. And it seems a lot of stuff has changed since the last time I coded and I’m a bit confused about what I need to change in order for this ping slash command to work.

Error Expected the value to be an object, but received string instead

Code

const { EmbedBuilder } = require("discord.js");

module.exports = {
  name: "ping",
  description: "Displays Crimson's API and Latency ping!",
  options: null,
  run: async (client, interaction, args) => {    
    const pingEmbed1 = new EmbedBuilder()
      .setTitle("Pinging...")
      .setColor("#fb644c");

    const pingMsg = await interaction.reply({ embeds: [pingEmbed1], fetchReply: true });

    try {      
      const pingEmbed2 = new EmbedBuilder()
        .setTitle("Pong!")
        .setDescription(`⌛ Latency: \`${Math.floor(pingMsg.createdTimestamp - interaction.createdTimestamp)}ms\`\n⏲️ API: \`${Math.round(client.ws.ping)}ms\``)
        .setFooter(`Command Requested by: ${interaction.user.tag}`, interaction.user.displayAvatarURL())
        .setColor("#fb644c");
      await interaction.editReply({ embeds: [pingEmbed2] });
    } catch (err) {
        console.log(err);
        return interaction.editReply(`\`${err.message}\`.`);
    }
  },
};

Now just to be clear, so people don’t get mad at me for not trying… I did change a few things that were changed such as the new embed builder and so on.


Solution

  • In discord.js v14, EmbedBuilder#setFooter() accepts a sole FooterOptions object. You will need to provide an object with a text and an iconURL keys:

    const pingEmbed2 = new EmbedBuilder()
      .setTitle('Pong!')
      .setDescription(
        `⌛ Latency: \`${Math.floor(
          pingMsg.createdTimestamp - interaction.createdTimestamp,
        )}ms\`\n⏲️ API: \`${Math.round(client.ws.ping)}ms\``,
      )
      .setFooter({
        text: `Command Requested by: ${interaction.user.tag}`,
        iconURL: interaction.user.displayAvatarURL(),
      })
      .setColor('#fb644c');