javascript - 我有一个错误,但我没有找到问题
问题描述
我想执行这个命令,但是当我执行这个命令时,我有这个错误消息:错误代码:
(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"
}
你能帮我吗 ?
解决方案
错误本身已经告诉你了。出现错误的原因是由于未处理的承诺拒绝。
原因:
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.
错误信息通常会得到答案,学习如何阅读它们非常重要。我还在学习如何阅读它。希望能帮助到你。
材料:
- Ian Segers 在 JS 中使用 Async/Await 处理错误,链接
推荐阅读
- rest - RestApi 中的 Put Request 的 Null 值
- python - 如何用另一个数组的同一索引中的值替换一个数组中的值?
- php - 如何使用此 GeoJson 文件从特定国家/地区生成随机点(坐标)?
- feature-extraction - 使用 Featuretools 聚合一天中的每个时间
- c++ - 在除构造函数之外的任何其他地方访问相机时,我的相机指针返回 null
- c# - 生成的小行星向生成时发现的玩家位置移动,但不会更远
- c# - 停止 IOS 在 Xamarin.Forms 中弹跳
- postgresql - Heroku Postgres pg:backups 从副本恢复
- php - 即使使用单例设计模式,PHP 类也会实例化两次
- python - 将结构化文本文件转换为 CSV