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:
JavaScript
x
48
48
1
let title = interaction.options.getString('song');
2
3
await interaction.deferReply();
4
5
if(!title){
6
if(!queue.playing()){
7
return await interaction.followUp(
8
'Please provide a valid song and try again!'
9
)
10
}
11
title = queue.nowPlaying();
12
}
13
14
function substring(length, value){
15
const replaced = value.replace('/n/g', '--');
16
const regex = `.{1,${length}}`;
17
const lines = replaced
18
.match(new RegExp(regex, "g"))
19
.map(line => line.replace(/--/g, 'n'));
20
21
return lines;
22
}
23
24
const songTitle = title; // The name of the song
25
26
const url = await new URL('https://some-random-api.ml/lyrics'); // The API
27
url.searchParams.append('title', songTitle);
28
console.log("url: ", url);
29
30
try{
31
const { data } = await axios.get(url.href);
32
const embeds = substring(500, data.lyrics).map((value, index) => {
33
const isFirst = index === 0; // add title and thumbnail to first embed only
34
35
return new EmbedBuilder({
36
title: isFirst ? `${data.title} - ${data.author}`: null,
37
// thumbnail: isFirst ? `${interaction.user.displayAvatarURL}`: null,
38
description: value,
39
})
40
});
41
42
return await interaction.followUp({embeds}); // Something is going wrong here I think
43
} catch(err){
44
console.log(err)
45
interaction.followUp({content: 'Sorry but I am not able to find lyrics for that song title',
46
})
47
}
48
It also gives me this error:
JavaScript
1
5
1
24.09 22:43:07 [Bot] code: 50035,
2
24.09 22:43:07 [Bot] errors: { embeds: [Object] },
3
24.09 22:43:07 [Bot] message: 'Invalid Form Body'
4
24.09 22:43:07 [Bot] },
5
I tried changing the object to be like
JavaScript
1
2
1
return await interaction.followUp({EmbedBuilder: embeds})
2
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:
JavaScript
1
2
1
await interaction.deferReply();
2
To reply to a deferred interaction, you should use the interaction#editReply
method instead.