【问题标题】:DiscordAPIError: Invalid Form Body embed.image.url: Scheme "[object response]" is not supported. Scheme must be one of ('http', 'https')DiscordAPIError:无效的表单正文 embed.image.url:不支持方案“[对象响应]”。方案必须是 ('http', 'https') 之一
【发布时间】:2021-08-17 06:48:46
【问题描述】:

所以我尝试使用以下代码从 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)));
            });
        }

    }

我知道我犯了一个巨大的错误,但我想更多地了解这个错误以及我做错了什么。 谢谢

【问题讨论】:

    标签: javascript api discord discord.js chart.js


    【解决方案1】:

    您必须提供一个图像 url,而不是您当前的 fetch 尝试获取图像的位置,您必须提供快速图表链接,如下所示:

    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
    }
    

    【讨论】:

    • 啊,谢谢它的工作,但我也解决了它,我使用 npm 包 quickchart-js 代替,更方便!
    猜你喜欢
    • 2021-06-16
    • 1970-01-01
    • 2017-05-27
    • 2021-04-20
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-09
    相关资源
    最近更新 更多