I am making a discord bot that will fetch a quotes from api and then return it as a discord reply code ->
const { SlashCommandBuilder } = require("@discordjs/builders");
const fetch = async (...args) =>
import("node-fetch")
.then(({ default: fetch }) =>
fetch("https://animechan.vercel.app/api/random"))
.then((res) => res = JSON.stringify(res))
.then((res) => {return res});
async function main(){
data = await fetch()
console.log(data);
return data
}
quote= main()
console.log(quote)
quote= JSON.stringify(quote);
console.log(typeof(quote))
console.log(quote)
module.exports = {
data: new SlashCommandBuilder()
.setName("ani-quote")
.setDescription("Gives a random anime quote"),
async execute(interaction) {
const sent = await interaction.reply({
content: quote,
});
},
};
I am these the problem
the variable "quote" is a promise that is pending and then when I try
quote= JSON.stringify(quote);
it turns the promise into string with{}
is there anyway to fix this? so that the stringify is run after the promise is full filledthe quote is regenerated only when the bot starts