Skip to content
Advertisement

DiscordAPIError[50035]: Invalid Form Body, errors: { embeds: [Object]

So I am trying to get the lyrics of a song (which works), but because of the 4096 characters limit on discord I have to cut it into different pieces. However, when I try to send all of the messages it gives me the error: DiscordAPIError[50035]: Invalid Form Body

This is the code that I am using:

let title = interaction.options.getString('song');

        await interaction.deferReply();

        if(!title){
            if(!queue.playing()){
                return await interaction.followUp(
                    'Please provide a valid song and try again!'
                )
            }
            title = queue.nowPlaying();
        }
        
        function substring(length, value){
          const replaced = value.replace('/n/g', '--');
          const regex = `.{1,${length}}`;
          const lines = replaced
            .match(new RegExp(regex, "g"))
            .map(line => line.replace(/--/g, 'n'));

            return lines;
        }

        const songTitle = title; // The name of the song

        const url = await new URL('https://some-random-api.ml/lyrics'); // The API
        url.searchParams.append('title', songTitle);
        console.log("url: ", url);

        try{
            const { data } = await axios.get(url.href);
            const embeds = substring(500, data.lyrics).map((value, index) => {
              const isFirst = index === 0; // add title and thumbnail to first embed only

              return new EmbedBuilder({ 
                 title: isFirst ? `${data.title} - ${data.author}`: null,
                 // thumbnail: isFirst ? `${interaction.user.displayAvatarURL}`: null,
                 description: value,
              })
            });

            return await interaction.followUp({embeds}); // Something is going wrong here I think
        } catch(err){
            console.log(err)
            interaction.followUp({content: 'Sorry but I am not able to find lyrics for that song title',
          })
        }

It also gives me this error:

24.09 22:43:07 [Bot] code: 50035,
24.09 22:43:07 [Bot] errors: { embeds: [Object] },
24.09 22:43:07 [Bot] message: 'Invalid Form Body'
24.09 22:43:07 [Bot] },

I tried changing the object to be like

return await interaction.followUp({EmbedBuilder: embeds})

But that would just say I cannot send an empty message. Any help is appreciated thanks!

Advertisement

Answer

At the top of your code, you have deferred the reply:

   await interaction.deferReply();

To reply to a deferred interaction, you should use the interaction#editReply method instead.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement