为什么我在使用 Discord API 时收到 Invalid Form Body 错误?

时间:2021-06-17 16:08:03

标签: javascript node.js discord discord.js

我正在制作一个不和谐的机器人,但是当我创建一个 ping 命令时,它会显示以下内容:

(node:37584) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
embed.footer.icon_url: Scheme "flashybot" is not supported. Scheme must be one of ('http', 'https').
embeds[0].footer.icon_url: Scheme "flashybot" is not supported. Scheme must be one of ('http', 'https').
    at RequestHandler.execute (C:\Users\niels\Documents\VsCode Projects\Discord Bots\FlashyBot\node_modules\discord.js\src\rest\RequestHandler.js:154:13)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async RequestHandler.push (C:\Users\niels\Documents\VsCode Projects\Discord Bots\FlashyBot\node_modules\discord.js\src\rest\RequestHandler.js:39:14)
    at async callback (C:\Users\niels\Documents\VsCode Projects\Discord Bots\FlashyBot\commands\misc\ping.js:15:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:37584) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:37584) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我的 ping.js 代码是:

const { MessageEmbed } = require("discord.js")

module.exports = {
    commands: ["ping", 'pong'],
    expectedArgs: "",
    permissionError: '',
    minArgs: 0,
    maxArgs: null,
    callback: async(message, args, text, client) => {
        let pinging = new MessageEmbed()
            .setTitle('Pinging....')
            .setColor("RED")
            .setFooter(client.user.avatarURL(), client.user.username)

        const msg = await message.channel.send(pinging)

        let embed = new MessageEmbed()
            .setTitle('Pong! ?')
            .addField("Api Latency", `${Math.floor(message.createdTimestamp - message.createdTimestamp)}ms`)
            .addField("Latency", `${Math.floor(client.ws.ping)}ms`)
            .setColor("LIGHT_GREEN")
            .setFooter(client.user.avatarURL(), client.user.username)
            .setTimestamp()

        msg.edit(embed)
    }
}

有人可以帮我解决这个问题吗?我尝试执行 message.client.user.avatarURL() 和 displayAvatarURL() 函数,但它一直出现此错误

1 个答案:

答案 0 :(得分:0)

你的日志说 embed.footer.icon_url: Scheme "flashybot" is not supported. Scheme must be one of ('http', 'https'). embeds[0].footer.icon_url: Scheme "flashybot" is not supported. Scheme must be one of ('http', 'https'). 这似乎表明为您的图标提供的 url 不正确(并且不以 http 或 https 开头,这是必需的)。

我认为这是不正确的 client.user.avatarURL(),尝试用硬编码图片链接替换它,看看是否有帮助。您可能在 avatarURL 中的值不正确...