so im working on a bot that shows data from an api.
This is my code:
if (message.content.startsWith(Config.prefix + 'Test')) {
let uuid;
axios
.get("https://api.hypixel.net/player?name=dkdg&key=MYKEY")
.then((res) => {
uuid = res.data.player.uuid;
})
.catch((err) => {
console.log("ERR:", err)
})
if (!uuid) return;
const Embed = new Discord.MessageEmbed()
.setColor('#e0a467')
.setTitle('Test')
.setDescription("UUID:" + uuid)
message.channel.send(Embed);
}
The issue here is that the bot doesn't send the embed. How can i fix this?
Try putting all of the code inside .then()
, like this:
if (message.content.startsWith(Config.prefix + 'Test')) {
axios
.get("https://api.hypixel.net/player?name=dkdg&key=MYKEY")
.then((res) => {
let uuid = res.data.player.uuid;
if (!uuid) return;
const Embed = new Discord.MessageEmbed()
.setColor('#e0a467')
.setTitle('Test')
.setDescription("UUID:" + uuid)
message.channel.send(Embed);
})
.catch((err) => {
console.log("ERR:", err)
})
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.