首页 > 解决方案 > 为什么 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,但无济于事。有人可以告诉我问题是什么吗?

标签: node.jsdiscorddiscord.jsbots

解决方案


这是当 Web 请求长时间卡住时 discord.js 库中发生的错误,这可能是由于中断或互联网连接不良而发生的。它可以被忽略,因为它不会杀死程序,但是您可以尝试将代码放在 try/catch 语句中以避免它。


推荐阅读