【发布时间】:2021-05-14 10:22:26
【问题描述】:
我创建了一个命令来获取给定加密货币的价格数据。当我运行我的命令时,嵌入对于每个价格值都有“未定义”。
这是我的代码:
module.exports = {
name: 'crypto',
description: 'gets crypto data',
async execute (message, args) {
let cc = args.slice(0).join(' ');
const noArgs = new Discord.MessageEmbed()
.setTitle('Missing arguments')
.setColor((Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'))
.setDescription('You are missing some args (ex: -crypto bitcoin || -covid dogecoin)')
.setTimestamp(new Date().getTime())
if(!cc) return message.channel.send(noArgs);
await fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${cc}&vs_currencies=usd%2Ceur%2Cgbp`)
.then (response => response.json)
.then(data => {
let usdprice = data.usd
let europrice = data.eur
let gbpprice = data.gbp
const embed = new Discord.MessageEmbed()
.setTitle(`**Current price of ${cc}:**`)
.setDescription('This data might be inaccurate.')
.setColor((Math.random() * 0xFFFFFF << 0).toString(16).padStart(6, '0'))
.setTimestamp(new Date().getTime())
.addField('**USD:**', usdprice, true)
.addField('**EURO:**', europrice, true)
.addField('**GBP:**', gbpprice, true)
message.channel.send(embed)
})
}
}
运行命令时控制台也没有错误。
【问题讨论】:
-
你检查过
cc的值和返回的data吗?
标签: javascript node.js discord discord.js