Recently, I embarked on a project to create a Discord bot using DiscordJS. My goal was to fetch some data from the Steam API and then embed it within my bot. However, upon running the code, I encountered an issue where the embedded fields appeared empty. It seems that the problem arises because the request takes time for the data to arrive, causing the strings to remain empty when the code moves on.
The particular error message I received in the terminal is as follows:
RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values must be non-empty strings.
const gtaUrl = 'https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?key=KEY&format=json&appid=271590';
let gtaData = '';
request(gtaUrl, function(err, res, body) {
if (!err && res.statusCode < 400) {
gtaData += body;
}
});
const exampleEmbed = new MessageEmbed()
.setColor('#0099ff')
.setTitle('Showing concurrent player numbers for some games')
.setDescription('the game')
.setThumbnail('https://i.imgur.com/FNviTdG.jpeg')
.addFields(
{ name: 'tf2 ', value: gtaData },
)
.addField('Inline field title', 'Some value here', true)
.setImage('https://i.imgur.com/AfFp7pu.png')
.setTimestamp();
message.channel.send({ embeds: [exampleEmbed] });
As I delve into this intricate world of JavaScript, I am still grappling with some concepts, especially since I am utilizing Express for the request part of my project. Despite the challenges, I am determined to troubleshoot the issue at hand and enhance my bot's functionality.