skip to Main Content

I’m building a serverinfo slash command with an embed builder for my discord bot however I’m coming across this error which may be due to my .addFields section of my code. The following is the error I get when testing the command:

CombinedPropertyError (5)
  Received one or more errors

  input[1]
  | CombinedPropertyError (1)
  |   Received one or more errors
  | 
  |   input.value
  |   | ValidationError > s.string
  |   |   Expected a string primitive
  |   | 
  |   |   Received:
  |   |   | 16

  input[2]
  | CombinedPropertyError (1)
  |   Received one or more errors
  | 
  |   input.value
  |   | ValidationError > s.string
  |   |   Expected a string primitive
  |   | 
  |   |   Received:
  |   |   | 1

  input[3]
  | CombinedPropertyError (1)
  |   Received one or more errors
  | 
  |   input.value
  |   | ValidationError > s.string
  |   |   Expected a string primitive
  |   | 
  |   |   Received:
  |   |   | 5

  input[4]
  | CombinedPropertyError (1)
  |   Received one or more errors
  | 
  |   input.value
  |   | ValidationError > s.string
  |   |   Expected a string primitive
  |   | 
  |   |   Received:
  |   |   | 2

  input[5]
  | CombinedPropertyError (1)
  |   Received one or more errors
  | 
  |   input.value
  |   | ValidationError > s.string
  |   |   Expected a string primitive
  |   | 
  |   |   Received:
  |   |   | 2

    at ArrayValidator.handle (/home/runner/tester/node_modules/@sapphire/shapeshift/dist/index.js:468:70)
    at ArrayValidator.parse (/home/runner/tester/node_modules/@sapphire/shapeshift/dist/index.js:207:88)
    at EmbedBuilder.addFields (/home/runner/tester/node_modules/@discordjs/builders/dist/index.js:222:31)
    at Object.execute (/home/runner/tester/commands/info/serverinfo.js:21:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

I have no idea what it could be at this point. Here is the code I have written:

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

  module.exports = {
    data: new SlashCommandBuilder()
      .setName("serverinfo")
      .setDescription("Provides information about the server.")
      .setDMPermission(false),
  
    async execute(client, interaction) {
      const { guild } = interaction;
      const { members, channels, emojis, roles, stickers } = guild;
  
      const embed = new EmbedBuilder()
        .setColor("#2B2D31")
        .setTitle(`${guild.name} - Server info`)
        .setThumbnail(guild.iconURL({ size: 256 }))
        .setImage(guild.bannerURL({ size: 256 }))
        .addFields(
          { name: "Owner", value: (await guild.fetchOwner()).user.tag, inline: true },
          { name: "Text Channels", value: guild.channels.cache.filter((c) => c.type === 0).toJSON().length, inline: true },
          { name: "Voice Channels", value: guild.channels.cache.filter((c) => c.type === 2).toJSON().length, inline: true },
          { name: "Category Channels", value: guild.channels.cache.filter((c) => c.type === 4).toJSON().length, inline: true },
          { name: "Members", value: guild.memberCount, inline: true },
          { name: "Roles", value: guild.roles.cache.size, inline: true },
          { name: "Role List", value: guild.roles.cache.toJSON().join(', ')},
        );
      interaction.reply({ embeds:  });
    },
  };

Any ideas? Thanks in advance

2

Answers


  1. The .addFields method uses an array of objects. You’ve probably forgot your square brackets. Just add them in the following places:

    .addFields( // <- Here
              { name: "Owner", value: (await guild.fetchOwner()).user.tag, inline: true },
              { name: "Text Channels", value: guild.channels.cache.filter((c) => c.type === 0).toJSON().length, inline: true },
              { name: "Voice Channels", value: guild.channels.cache.filter((c) => c.type === 2).toJSON().length, inline: true },
              { name: "Category Channels", value: guild.channels.cache.filter((c) => c.type === 4).toJSON().length, inline: true },
              { name: "Members", value: guild.memberCount, inline: true },
              { name: "Roles", value: guild.roles.cache.size, inline: true },
              { name: "Role List", value: guild.roles.cache.toJSON().join(', ')},
            ); // <- Here too
    

    Here it is fixed:

    .addFields([ // <- Here
              { name: "Owner", value: (await guild.fetchOwner()).user.tag, inline: true },
              { name: "Text Channels", value: guild.channels.cache.filter((c) => c.type === 0).toJSON().length, inline: true },
              { name: "Voice Channels", value: guild.channels.cache.filter((c) => c.type === 2).toJSON().length, inline: true },
              { name: "Category Channels", value: guild.channels.cache.filter((c) => c.type === 4).toJSON().length, inline: true },
              { name: "Members", value: guild.memberCount, inline: true },
              { name: "Roles", value: guild.roles.cache.size, inline: true },
              { name: "Role List", value: guild.roles.cache.toJSON().join(', ')},
            ]); // <- Here too
    

    Often the most simple mistakes are the ones that catch us out.

    Stick a comment below if this doesn’t fix. Happy coding!

    Login or Signup to reply.
  2. The error is pretty straight-forward. Field values should be string primitives but you provide numbers. All those .length properties, guild.memberCount and cache.size are numbers.

    To fix this, you’ll need to convert them to strings. Also, you don’t need to use .toJSON() as filter() returns a collection, you can use the size property instead:

    const embed = new EmbedBuilder()
      .setColor('#2B2D31')
      .setTitle(`${guild.name} - Server info`)
      .setThumbnail(guild.iconURL({ size: 256 }))
      .setImage(guild.bannerURL({ size: 256 }))
      .addFields(
        { name: 'Owner', value: (await guild.fetchOwner()).user.tag, inline: true },
        {
          name: 'Text Channels',
          value: guild.channels.cache.filter((c) => c.type === 0).size.toString(),
          inline: true,
        },
        {
          name: 'Voice Channels',
          value: guild.channels.cache.filter((c) => c.type === 2).size.toString(),
          inline: true,
        },
        {
          name: 'Category Channels',
          value: guild.channels.cache.filter((c) => c.type === 4).size.toString(),
          inline: true,
        },
        { name: 'Members', value: guild.memberCount.toString(), inline: true },
        { name: 'Roles', value: guild.roles.cache.size.toString(), inline: true },
        { name: 'Role List', value: guild.roles.cache.toJSON().join(', ') },
      );
    

    You could also use template literals like this if you prefer them:

    {
      name: 'Text Channels',
      value: `${guild.channels.cache.filter((c) => c.type === 0).size}`,
      inline: true,
    },
    // ...
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search