discord.js heroku 除了嵌入式命令外,一切正常,怎么了?

Posted

技术标签:

【中文标题】discord.js heroku 除了嵌入式命令外,一切正常,怎么了?【英文标题】:discord.js heroku Everything works except embedded commands, what's wrong? 【发布时间】:2020-09-02 00:06:56 【问题描述】:

我能够按照教程让我的机器人上线,但它不运行任何命令。如果我在本地运行它,我的整个机器人可以完美运行。我想托管它以 24/7 运行!

这是尾日志(idk 如何从 GIT CMD 复制粘贴文本,抱歉,应该很清楚) https://i.stack.imgur.com/dFHNa.png

我可以让机器人为正常的消息回复 (bot.on('message', msg => ) 工作,但是一旦我尝试使用前缀命令,它就会杀死机器人并且无法运行任何东西。

这是我在 heroku 日志中的应用日志:

2020-05-16T16:03:21.760723+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-16T16:03:21.764281+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-16T16:03:21.687320+00:00 app[web.1]: I don't want a web process
2020-05-16T16:03:27.931832+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-16T16:03:27.853628+00:00 app[web.1]: I don't want a web process
2020-05-16T16:03:40.891630+00:00 app[worker.1]: /app/node_modules/discord.js/src/structures/MessageEmbed.js:443
2020-05-16T16:03:40.891638+00:00 app[worker.1]:       .flat(2)
2020-05-16T16:03:40.891639+00:00 app[worker.1]:        ^
2020-05-16T16:03:40.891639+00:00 app[worker.1]: 
2020-05-16T16:03:40.891640+00:00 app[worker.1]: TypeError: fields.flat is not a function
2020-05-16T16:03:40.891642+00:00 app[worker.1]:     at Function.normalizeFields (/app/node_modules/discord.js/src/structures/MessageEmbed.js:443:8)
2020-05-16T16:03:40.891643+00:00 app[worker.1]:     at MessageEmbed.addFields (/app/node_modules/discord.js/src/structures/MessageEmbed.js:259:42)
2020-05-16T16:03:40.891643+00:00 app[worker.1]:     at MessageEmbed.addField (/app/node_modules/discord.js/src/structures/MessageEmbed.js:250:17)
2020-05-16T16:03:40.891644+00:00 app[worker.1]:     at Object.execute (/app/commands/uhelp.js:9:14)
2020-05-16T16:03:40.891644+00:00 app[worker.1]:     at Client.bot.on.message (/app/index.js:44:39)
2020-05-16T16:03:40.891644+00:00 app[worker.1]:     at Client.emit (events.js:203:15)
2020-05-16T16:03:40.891645+00:00 app[worker.1]:     at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-05-16T16:03:40.891646+00:00 app[worker.1]:     at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-05-16T16:03:40.891647+00:00 app[worker.1]:     at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
2020-05-16T16:03:40.891648+00:00 app[worker.1]:     at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
2020-05-16T16:03:40.903134+00:00 app[worker.1]: npm ERR! code ELIFECYCLE
2020-05-16T16:03:40.904074+00:00 app[worker.1]: npm ERR! errno 1
2020-05-16T16:03:40.906913+00:00 app[worker.1]: npm ERR! et@1.0.0 start: `node index.js`
2020-05-16T16:03:40.907263+00:00 app[worker.1]: npm ERR! Exit status 1
2020-05-16T16:03:40.907770+00:00 app[worker.1]: npm ERR! 
2020-05-16T16:03:40.908137+00:00 app[worker.1]: npm ERR! Failed at the et@1.0.0 start script.
2020-05-16T16:03:40.908482+00:00 app[worker.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-05-16T16:03:40.929856+00:00 app[worker.1]: 
2020-05-16T16:03:40.930071+00:00 app[worker.1]: npm ERR! A complete log of this run can be found in:
2020-05-16T16:03:40.930236+00:00 app[worker.1]: npm ERR!     /app/.npm/_logs/2020-05-16T16_03_40_922Z-debug.log
2020-05-16T16:03:41.019903+00:00 heroku[worker.1]: State changed from up to crashed
2020-05-16T16:03:41.024710+00:00 heroku[worker.1]: State changed from crashed to starting
2020-05-16T16:03:44.579866+00:00 heroku[worker.1]: State changed from starting to up
2020-05-16T16:03:46.362272+00:00 app[worker.1]: 
2020-05-16T16:03:46.362287+00:00 app[worker.1]: > et@1.0.0 start /app
2020-05-16T16:03:46.362288+00:00 app[worker.1]: > node index.js

已编辑日志

编辑:所以主要问题是,我无法运行嵌入式命令。你怎么修?我刚刚重新安装了最新的 node.js 版本(它没有做任何事情)。

非常感谢您!

第二次编辑 - 新日志:(节点版本 v12.16.3 ; Discord.js 版本 discord.js@12.2.0)

2020-05-17T21:52:04.952421+00:00 heroku[worker.1]: Restarting
2020-05-17T21:52:04.978162+00:00 heroku[worker.1]: State changed from up to starting
2020-05-17T21:52:08.718818+00:00 heroku[worker.1]: State changed from starting to up
2020-05-17T21:52:10.768031+00:00 app[worker.1]: This bot is online!
2020-05-17T21:53:07.574666+00:00 app[worker.1]: /app/node_modules/discord.js/src/structures/MessageEmbed.js:443
2020-05-17T21:53:07.574686+00:00 app[worker.1]:       .flat(2)
2020-05-17T21:53:07.574687+00:00 app[worker.1]:        ^
2020-05-17T21:53:07.574687+00:00 app[worker.1]: 
2020-05-17T21:53:07.574689+00:00 app[worker.1]: TypeError: fields.flat is not a function
2020-05-17T21:53:07.574690+00:00 app[worker.1]:     at Function.normalizeFields (/app/node_modules/discord.js/src/structures/MessageEmbed.js:443:8)
2020-05-17T21:53:07.574690+00:00 app[worker.1]:     at MessageEmbed.addFields (/app/node_modules/discord.js/src/structures/MessageEmbed.js:259:42)
2020-05-17T21:53:07.574691+00:00 app[worker.1]:     at MessageEmbed.addField (/app/node_modules/discord.js/src/structures/MessageEmbed.js:250:17)
2020-05-17T21:53:07.574691+00:00 app[worker.1]:     at Object.execute (/app/commands/uhelp.js:9:14)
2020-05-17T21:53:07.574691+00:00 app[worker.1]:     at Client.bot.on.message (/app/index.js:44:39)
2020-05-17T21:53:07.574692+00:00 app[worker.1]:     at Client.emit (events.js:203:15)
2020-05-17T21:53:07.574692+00:00 app[worker.1]:     at MessageCreateAction.handle (/app/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
2020-05-17T21:53:07.574693+00:00 app[worker.1]:     at Object.module.exports [as MESSAGE_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
2020-05-17T21:53:07.574694+00:00 app[worker.1]:     at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
2020-05-17T21:53:07.574694+00:00 app[worker.1]:     at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:436:22)
2020-05-17T21:53:07.640438+00:00 heroku[worker.1]: State changed from up to crashed
2020-05-17T21:53:07.643659+00:00 heroku[worker.1]: State changed from crashed to starting
2020-05-17T21:53:10.940344+00:00 heroku[worker.1]: State changed from starting to up
2020-05-17T21:53:12.813527+00:00 app[worker.1]: This bot is online!

【问题讨论】:

从错误来看,有些东西正试图攻击你的机器人,就像它是一个网络服务器一样,它正在崩溃。我们需要查看更多代码,然后才能告诉您一些有用的信息。 嵌入似乎有问题。这是我引用的帖子:***.com/questions/60934727/… 我正在添加一些代码并尝试修复它,当我推送时,我看到了这个 ``` 远程:-----> 远程安装二进制文件:engines.node (package.json ):10.x远程:engines.npm(package.json):*远程:远程:解析节点版本10.x ...远程:下载和安装节点10.20.1 ...远程:引导npm *(替换6.14 .4)... remote: npm * installed ``` 它安装节点版本 10?它应该是版本 12 还是?如何解决? 【参考方案1】:

您的机器人无法作为网络服务启动,因为它不是网络服务。 Excerpt from this medium article 第 3 部分。

Step 1: Go to the Heroku Dashboard
[....]
Step 3: Under Resources, deselect web and activate the worker

【讨论】:

我已取消选择 web 并激活了 worker。我仍然无法使用嵌入式命令。由于无法在评论中发送,我已将新日志编辑到底部的帖子中。

以上是关于discord.js heroku 除了嵌入式命令外,一切正常,怎么了?的主要内容,如果未能解决你的问题,请参考以下文章

当机器人托管在 heroku 上时如何制作 discord.js 图像搜索命令

Heroku/Discord.js 错误“服务不可用”

错误:在 Heroku 上找不到模块 Discord.js

在 Heroku 上托管 discord.js 机器人

Discord.js 我的机器人在 Heroku 上托管时找不到任何父或子频道

嵌入命令(颜色)(discord.js-commando)