启动不和谐机器人时出现问题(它不想工作)



这是我第一次做一个真正的javascript项目(我以前使用过一点js,但仅此而已)。我在试着制造一个不和谐的机器人。我把它托管在heroku上,在部署我的项目时,我得到了一个我无法解决的错误。以下是日志中的内容:

2021-08-20T13:01:23.972825+00:00 heroku[worker.1]: Starting process with command `node index.js`
2021-08-20T13:01:23.771024+00:00 heroku[web.1]: Starting process with command `npm start`
2021-08-20T13:01:24.646055+00:00 heroku[worker.1]: State changed from starting to up
2021-08-20T13:01:27.027743+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined
2021-08-20T13:01:27.027754+00:00 app[worker.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:172:15)
2021-08-20T13:01:27.027754+00:00 app[worker.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:176:19)
2021-08-20T13:01:27.027755+00:00 app[worker.1]:     at RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:50:25)
2021-08-20T13:01:27.027755+00:00 app[worker.1]:     at async WebSocketManager.connect (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:128:9)
2021-08-20T13:01:27.027755+00:00 app[worker.1]:     at async Client.login (/app/node_modules/discord.js/src/client/Client.js:245:7)
2021-08-20T13:01:27.027756+00:00 app[worker.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-08-20T13:01:27.028065+00:00 app[worker.1]: (node:4) 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)
2021-08-20T13:01:27.028108+00:00 app[worker.1]: (node:4) [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.

我已经在我的电脑上有这个错误,我刚刚改进了node的版本,我没有更多的错误。然而,我不知道该怎么对付英雄。此外,当我在电脑上修复错误时,它似乎可以工作,但是当我输入'!Ping ' bot没有回答我,on discord。

所以我有两个问题:

  1. UnhandledPromiseRejectionWarning',在heroku上
  2. 我的机器人不工作

有人能帮帮我吗?

版本如下:

node : v16.7.0
discord.js : v13.1.0
下面是我的代码:

index.js

const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS
]
});
const prefixCmd = '!';
client.on("ready", () => {
console.log("I'm ready !");
});
client.on("message", msg => {
if(!msg.content.startsWith(prefixCmd) || msg.author.bot) return
const args = msg.content.slice(prefixCmd.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === "ping") {
msg.reply("pong");
}
});
client.login("MY TOKEN");

package.json

{
"name": "ha",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"discord.js": "^13.1.0",
"node": "^16.6.0"
},
"devDependencies": {},
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/......"
},
"author": "",
"license": "ISC"
}

要解决这个问题,您必须添加:

"engines": {
"node": "16.7.0" 
}

到package.json

要使heroku工作,您需要从package.json中的依赖项中删除node。

并在包中添加。json:

"engines": {
"node": "16.7.0" 
}

要让bot运行,你不能写:

const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
Intents.FLAGS.GUILDS
]
});

但是你必须写:

const { Client, Intents } = require('discord.js');
const client = new Client({
intents: [
"GUILDS",
"GUILD_MESSAGES",
"DIRECT_MESSAGES"
],
partials: [
"CHANNEL"
]
});

最新更新