I have added a API response to my Discord Bot and want to know how to format this API response into a embed to make it look nice when it gets sent in Discord
Here is my code:
const ifliveService = require("../utils/InfiniteFlightLive")
const ifl = new ifliveService()
module.exports = {
category: "Userstats",
description: "Fetches the users states from Discourse.",
expectedArgs: '<ifc username>',
minArgs: 1,
maxArgs: 1,
callback: async ({channel, args}) => {
const username = args[0]
const userstats = await ifl.getUserStats(username)
if(!userstats || userstats.result == []) return "Invalid user"
return JSON.stringify(userstats.result[0], null, '\t')
}
}
I want to return that base reply into a embed how would that be possible? Please note I am a bit of a beginner with all of this so I apologize if it is a quick and easy solution.
You can create an embed like this:
const { MessageEmbed } = require("discord.js");
const embed = new MessageEmbed()
.setTitle("Your title here")
.setDescription("Your description here")
.addField("Field name", "Field value");
// Using Discord.js v13
message.channel.send({ embeds: [ embed ] });
Add as many fields as you like using addField()
. You can learn more about embeds in the official documentation.