首页 > 解决方案 > 我有一个错误,但我没有找到问题

问题描述

我想执行这个命令,但是当我执行这个命令时,我有这个错误消息:错误代码:

    (node:8616) UnhandledPromiseRejectionWarning: Error: 400 Bad Request
    at C:\Users\Eleve\Desktop\FA Bot\node_modules\snekfetch\src\index.js:195:23
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:8616) 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: 2)
(node:8616) [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.

这是代码:

    const Discord = require("discord.js")
const botconfig = require("../botconfig.json");
const colours = require("../colours.json");
const prefix = botconfig.prefix
const webhook = require("webhook-discord")

module.exports.run = async (bot, message, args) => {

const Hook = new webhook.Webhook("https://discordapp.com/api/webhooks/689803124957118476/xiz3sE3dhQhjW7CoJrTIVB60LCckSHYm_0X9OwlGEQwDnmKYHzFuvekImwxjSaOuhoN-")
const msg = new webhook.MessageBuilder()
                .setName(message.author.username)
                .setColor("RANDOM")
                .setText("Test")
                .setTime();

Hook.send(msg)

}

module.exports.config = {
    name: "webhook",
    aliases: ["wh"],
    usage: "!usage",
    description: "",
    accessableby: "Membres"
}

你能帮我吗 ?

标签: javascriptnode.jsdiscord.js

解决方案


错误本身已经告诉你了。出现错误的原因是由于未处理的承诺拒绝

原因:

1. This error originated either by throwing inside of an async function without a catch block, or
2. by rejecting a promise which was not handled with .catch().

这意味着您可以通过以下方式处理问题:

1. You can move you async function into a try and catch block in order to catch the error when the function has failed 
2. You can add a .catch() chain function as node suggested. 

错误信息通常会得到答案,学习如何阅读它们非常重要。我还在学习如何阅读它。希望能帮助到你。

材料:

  1. Ian Segers 在 JS 中使用 Async/Await 处理错误,链接

推荐阅读