WildFyr
WildFyr

Reputation: 1

Discord.js slash commands with embeds

I am trying to build an embed with slash commands. This is an error I am getting and for the life of me I cannot figure out what is wrong. I know this embed itself works as I had it in the old bot and it ran fine, however as soon as I update the command handler it has stopped working. It seems that it is unable to find the embeds description yet I have one set so I am really unsure why it is not reading it

node_modules\discord.js\src\rest\RequestHandler.js:350
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Invalid Form Body
data.embeds[0].description: This field is required
    at RequestHandler.execute (node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (node_modules\discord.js\src\rest\RequestHandler.js:51:14) {
  method: 'post',
  path: '/interactions/987187176422907954/aW50ZXJhY3Rpb246OTg3MTg3MTc2NDIyOTA3OTU0OnBuWmNoTmVoOXltU0pydG9WOXpJenUzeTRPSDBybllDZEZSME9RandlOExpYlFFckRteG1sa1RVV2NycmhQbmpsenpRb1ZBdzhLQ3hGV09WR0dKcHI2QlQ2bjZMWFZWVVU3Q3pzN0tVT24xV1F6S1psVG41UGhWVHZYUzl4alZ4/callback',
  code: 50035,
  httpStatus: 400,
  requestData: {
    json: {
      type: 4,
      data: {
        content: undefined,
        tts: false,
        nonce: undefined,
        embed: {
          title: null,
          type: 'rich',
          description: null,
          url: null,
          timestamp: null,
          color: null,
          fields: [],
          thumbnail: null,
          image: null,
          author: null,
          footer: null
        },
        embeds: [
          {
            title: null,
            type: 'rich',
            description: null,
            url: null,
            timestamp: null,
            color: null,
            fields: [],
            thumbnail: null,
            image: null,
            author: null,
            footer: null
          }
        ],
        username: undefined,
        avatar_url: undefined,
        allowed_mentions: undefined,
        flags: undefined,
        files: []
      }
    },
    files: []
  }
}

And this is the code in question

const { Client, MessageEmbed } = require("discord.js");
const config = require("../settings/config")

module.exports = {
    slash: true,
    testOnly: true,
    description: "Gives latency of the bot",
    /**
     * 
     * @param {CommandInteration} interaction 
     * @param {Client} client
     */
    callback: async (interaction, client) => {
        const Build = new MessageEmbed()
        .setColor(config.settings.EmbedColour)
        .setTitle('**Ping / API Latency:**')
        .setDescription(`🏓 ${Date.now() - interaction.createdTimestamp}ms.`)
        .setFooter({ text: `${interaction.guild.name} | Made By WildFyr#0008`, iconURL: interaction.guild.iconURL({ dynamic: true }) })

        return ({embeds: [Build]})
    }
}

Does anyone know why I am getting this error and how to fix it? Here is the Config.js, I removed all tokens and IDs and what not

const config =  {
    settings: {
        Token: 'BOT TOKEN', //Visit https://discord.com/developers/applications and get your bots token
        LicenseKey: 'LICENSE KEY', //Visist https://license.wildfyr.net to get your keys
        BotApplicationID: 'BOT USER ID', //Bot's user ID
        BotOwnerID: 'USER ID', //Your user ID, used for Owner only commands
        GuildID: 'GUILD ID', //The ID for your Server
        EmbedColour: '#fc6a03', //The colour you want the side bar of the embeds to be
        botActivity: {
            status: 'online', //Online, idle, dnd, offline
            activity: {
                name: 'Whatever you want', //The name of the game the bot is playing
                type: 'PLAYING', //Playing, Watching, Streaming, Listening
            }
        },
        deleteCommands: 'TRUE', //Deletes the command after a set ammount of time, reduces chat spam
        ShowTriggeredEvents: 'FALSE', //Used for De-Bugging, prints in console everytime someone runs a command
    }
}

module.exports = config;

@新Acesyyy This is what I get after changing that.

commands\ping.js:15
        .setColor(config.settings[0].EmbedColour)
                                     ^

TypeError: Cannot read properties of undefined (reading 'EmbedColour')
    at Command.callback [as _callback] (commands\ping.js:15:38)
    at SlashCommands.<anonymous> (node_modules\wokcommands\dist\SlashCommands.js:177:54)
    at step (node_modules\wokcommands\dist\SlashCommands.js:44:23)
    at Object.next (node_modules\wokcommands\dist\SlashCommands.js:25:53)
    at node_modules\wokcommands\dist\SlashCommands.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules\wokcommands\dist\SlashCommands.js:15:12)
    at SlashCommands.invokeCommand (node_modules\wokcommands\dist\SlashCommands.js:168:16)
    at SlashCommands.<anonymous> (node_modules\wokcommands\dist\SlashCommands.js:67:26)
    at step (node_modules\wokcommands\dist\SlashCommands.js:44:23)
    at Object.next (node_modules\wokcommands\dist\SlashCommands.js:25:53)
    at node_modules\wokcommands\dist\SlashCommands.js:19:71
    at new Promise (<anonymous>)
    at __awaiter (node_modules\wokcommands\dist\SlashCommands.js:15:12)
    at WebSocketManager.<anonymous> (node_modules\wokcommands\dist\SlashCommands.js:58:86)
    at WebSocketManager.emit (node:events:390:28)

Upvotes: 0

Views: 3733

Answers (3)

Pascal
Pascal

Reputation: 23

DiscordAPIError: Invalid Form Body

The error is indicating that the embeds[0].description field is required, but it's not provided in your code. Looking at your callback function, you are creating a MessageEmbed but not setting the description field. You need to set the description field for the embed:

const Build = new MessageEmbed()
    .setColor(config.settings.EmbedColour)
    .setTitle('**Ping / API Latency:**')
    .setDescription(`🏓 ${Date.now() - interaction.createdTimestamp}ms.`)
    .setFooter(`${interaction.guild.name} | Made By WildFyr#0008`, interaction.guild.iconURL({ dynamic: true }));

Make sure to set the description field in the MessageEmbed instance.

TypeError: Cannot read properties of undefined (reading 'EmbedColour')

The error indicates that config.settings is undefined or not an object. This is likely due to a misconfiguration in your config.js. Make sure that config.settings is defined and is an object. You might want to change your config.js to the following:

const config =  {
    settings: {
        Token: 'BOT TOKEN',
        LicenseKey: 'LICENSE KEY',
        BotApplicationID: 'BOT USER ID',
        BotOwnerID: 'USER ID',
        GuildID: 'GUILD ID',
        EmbedColour: '#fc6a03',
        botActivity: {
            // ... rest of the properties
        },
        deleteCommands: 'TRUE',
        ShowTriggeredEvents: 'FALSE',
    }
}

module.exports = config;

Ensure that config.settings.EmbedColour is defined in your configuration.

Make these changes and see if it resolves your issues. If you still encounter problems, double-check your configuration and make sure all required fields are properly set.

Upvotes: 1

ChaosWraith
ChaosWraith

Reputation: 65

Your error message is showing that you're trying to access config.settings[0].EmbedColour which will return the first index object in the array.

However, it appears that config.settings is the only item in the config object.

config.settings.EmbedColour is the property you want to access.

Upvotes: 1

Ramy Hazem
Ramy Hazem

Reputation: 130

Maybe Instead of returning the embed, try replying to the interaction

interaction.reply({embeds: [Build]})

Upvotes: -1

Related Questions