Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord.js does not recognise the description of an embed

I’ve been making a custom bot for a server I’m in, and all was going well until I encountered this runtime error in code that was seemingly working fine. Any tips?

Error:

throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Invalid Form Body
embeds[0].description: This field is required
    at RequestHandler.execute (C:\Users\arinb\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\arinb\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async TextChannel.send (C:\Users\arinb\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:175:15) {
  method: 'post',
  path: '/channels/949653134551154718/messages',
  code: 50035,
  httpStatus: 400,
  requestData: {
    json: {
      content: undefined,
      tts: false,
      nonce: undefined,
      embeds: [
        {
          title: null,
          type: 'rich',
          description: null,
          url: null,
          timestamp: null,
          color: null,
          fields: [],
          thumbnail: null,
          image: null,
          author: null,
          footer: null
        }
      ],
      components: undefined,
      username: undefined,
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: undefined,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: []
  }
}

code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

client.on('interactionCreate', (interaction) => {
    let target = client.channels.cache.get(baseChannel) // gets channel 'general'
    let waitTrue = setWaitTime()
    if (!waitTrue) {
        console.log("sending success message")
        await interaction.reply({embeds: [
            new MessageEmbed()
                .setColor("DARK_BUT_NOT_BLACK")
                .setTitle("Current Status")
                .setDescription("OFF")              
        ]})
        target.send({components: [defaultMessage(serverState)] })
    } else {
        interaction.reply({embeds : [waitTrue]})
    }
}


function setWaitTime() {
    state = serverState
    let retValue = false
    if (state.minecraft.players + state.hlServer.players != 0 ){
        retValue = {embeds: [
            new MessageEmbed()
                .setColor("LUMINOUS_VIVID_PINK")
                .setDescription(`People are currently using the ${(state.minecraft.on) ? "minecraft": (state.hlServer.on) ? "TF2" : "ERROR"} server, try again later`)
                .setTitle("Queued your selection")
            ]
        }           
    }
    console.log(retValue)
    return retValue

I’m not sure why discord.js has not recognised the .setDescription(…) that has been applied to the embed, especially as this function was not changed since it worked…

>Solution :

After executing the setWaitTime() function, the value of the retValue variable is an object with an embed key and the value being the MessageEmbed so when you try to send retValue, what is actually happening is something like this:

interaction.reply({
    embeds: {
        embeds: {
            new MessageEmbed()
            // ...
        }
    }
})

which is why this particular error is happening. So to fix it, instead of sending retValue as the embed property, just send it by itself like this:

interaction.reply(retValue)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading