最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Expected the value to be an object, but received string instead - Stack Overflow

programmeradmin3浏览0评论

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 mand 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.

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 mand 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.

Share Improve this question edited Aug 1, 2022 at 6:00 Zsolt Meszaros 23.2k19 gold badges58 silver badges69 bronze badges asked Aug 1, 2022 at 4:07 Roman BeardRoman Beard 1032 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

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');
发布评论

评论列表(0)

  1. 暂无评论