node.js - 为什么 Discord.js Boiler Plate Bot 不起作用?
问题描述
我开始编写一个 Discord 机器人,我正在使用Discord.js 主页上提供的基本样板代码,即:
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content === 'ping') {
msg.reply('Pong!');
}
});
client.login('token');
但不幸的是,这不起作用。是的,我用机器人令牌替换了令牌。当我启动它时,它没有响应几秒钟,然后在调试器中弹出此错误。(我正在使用nodemon)
(node:14931) UnhandledPromiseRejectionWarning: AbortError: The user aborted a request.
at RequestHandler.execute (/home/sulphurouscerebrum/Projects/Discord Bot/Sulph Bot/node_modules/discord.js/src/rest/RequestHandler.js:93:15)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:14931) 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(). (rejection id: 3)
(node:14931) [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.
Waiting for the debugger to disconnect...
我尝试卸载并重新安装 Discord.js,但无济于事。有人可以告诉我问题是什么吗?
解决方案
这是当 Web 请求长时间卡住时 discord.js 库中发生的错误,这可能是由于中断或互联网连接不良而发生的。它可以被忽略,因为它不会杀死程序,但是您可以尝试将代码放在 try/catch 语句中以避免它。
推荐阅读
- svg - 无法更改样式 svg
- highcharts - 如何在箱线图高图中更改高低胡须颜色?
- html - 在同一行上对齐右(mat-icon)和左(文本)
- network-programming - 基于 LoRa 的网络堆栈替代 LoRaWAN
- reactjs - 如何使用 Redux 更改按钮
- angular - 在索引值处从 Angular 的数组中删除项目
- google-chrome-extension - 如何将二进制数据从 Google Chrome 扩展程序发送到本机应用程序
- javascript - 使用 React-Leaflet 拖动后无法访问多边形坐标
- excel - 更改功能区中自定义按钮的宏位置
- list - 如何将列表索引(网格)与片段元素进行比较?