所以我尝试使用以下代码从 quickchart.io 获取 .png 文件:
async exec(message, args) {
console.log(chalk.green("chart requested " + chalk.yellow(message.author.username) + " in " + chalk.magentaBright(message.channel.guild.name)));
console.log(args.coin)
const getChart = async () => {
const result = await fetch(`https://quickchart.io/chart?chart={
type: 'line',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Revenue',
data: [100, 200, 300, 400],fill:false
}]
}
}&backgroundColor=transparent&width=500&height=300&devicePixelRatio=1.0&format=png&version=2.9.3`)
const json = await result
return json
}
let com = await getChart()
if (message) {
let embed = new Discord.MessageEmbed()
.setImage(`${com}`)
message.channel.send({ embed }).catch(function (rej) {
message.channel.send("Sorry, I was unable to process this command. Make sure that I have full send permissions for embeds and messages and then try again!");
console.log(chalk.red('Error sending trending list! : ' + chalk.cyan(rej)));
});
}
}
我知道我犯了一个巨大的错误,但我想更多地了解这个错误以及我做错了什么。 谢谢
答案 0 :(得分:1)
您必须提供图像网址,以便您必须提供快速图表链接,而不是您当前尝试获取图像的位置,如下所示:
let com = `https://quickchart.io/chart?chart={
type: 'line',
data: {
labels: ['Q1', 'Q2', 'Q3', 'Q4'],
datasets: [{
label: 'Revenue',
data: [100, 200, 300, 400],fill:false
}]
}
}&backgroundColor=transparent&width=500&height=300&devicePixelRatio=1.0&format=png&version=2.9.3`
if (message) {
// rest of code
}