简体   繁体   中英

I've an error but I don't find the problem

I want execute this command, but when I execute this command, I've this error message : Error code :

    (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.

This is the 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"
}

Can you help me please ?

The error itself has already told you. The reason of having the error is due to Unhandled promise rejection .

Reasons:

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().

It means you can deal with the problem by:

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. 

Error msg usually got the answer, learning how to read them is very important. I am still learning how to read it. Hope it helps.

Materials:

  1. Error handling with Async/Await in JS by Ian Segers, link

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM