在 Heroku 上托管 discord.js 机器人

Posted

技术标签:

【中文标题】在 Heroku 上托管 discord.js 机器人【英文标题】:Hosting a discord.js bot on Heroku 【发布时间】:2020-06-27 00:53:45 【问题描述】:

我正在尝试在 Heroku 上存储一个不和谐机器人,但在应用运行时出现错误:

应用程序错误 应用程序发生错误,无法提供您的页面。如果您是应用程序所有者,请查看您的日志以获取详细信息。您可以从 Heroku CLI 使用以下命令执行此操作 heroku 日志 --tail.

我不知道是我遗漏了什么还是一个错误。

这是构建日志(我使用GitHub部署):

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false

-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 12.x...
       Downloading and installing node 12.16.1...
       Using default npm version: 6.13.4

-----> Restoring cache
       - node_modules is checked into source control and cannot be cached

-----> Installing dependencies
       Prebuild detected (node_modules already exists)
       Rebuilding any native modules

       > nodemon@2.0.2 postinstall /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/nodemon
       > node bin/postinstall || exit 0

       Love nodemon? You can now support the project via the open collective:
        > https://opencollective.com/nodemon/donate

       ascii-table@0.0.9 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ascii-table
       discord.js@12.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/discord.js
       @discordjs/collection@0.1.5 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/@discordjs/collection
       abort-controller@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/abort-controller
       event-target-shim@5.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/event-target-shim
       form-data@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/form-data
       asynckit@0.4.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/asynckit
       combined-stream@1.0.8 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/combined-stream
       delayed-stream@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/delayed-stream
       mime-types@2.1.26 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/mime-types
       mime-db@1.43.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/mime-db
       node-fetch@2.6.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/node-fetch
       prism-media@1.2.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/prism-media
       setimmediate@1.0.5 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/setimmediate
       tweetnacl@1.0.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/tweetnacl
       ws@7.2.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ws
       dotenv@8.2.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/dotenv
       fs@0.0.1-security /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/fs
       nodemon@2.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/nodemon
       chokidar@3.3.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/chokidar
       anymatch@3.1.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/anymatch
       normalize-path@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/normalize-path
       picomatch@2.2.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/picomatch
       braces@3.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/braces
       fill-range@7.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/fill-range
       to-regex-range@5.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/to-regex-range
       is-number@7.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-number
       glob-parent@5.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/glob-parent
       is-glob@4.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-glob
       is-extglob@2.1.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-extglob
       is-binary-path@2.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-binary-path
       binary-extensions@2.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/binary-extensions
       readdirp@3.3.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/readdirp
       debug@3.2.6 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/debug
       ms@2.1.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ms
       ignore-by-default@1.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ignore-by-default
       minimatch@3.0.4 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/minimatch
       brace-expansion@1.1.11 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/brace-expansion
       balanced-match@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/balanced-match
       concat-map@0.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/concat-map
       pstree.remy@1.1.7 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/pstree.remy
       semver@5.7.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/semver
       supports-color@5.5.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/supports-color
       has-flag@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/has-flag
       touch@3.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/touch
       nopt@1.0.10 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/nopt
       abbrev@1.1.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/abbrev
       undefsafe@2.0.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/undefsafe
       debug@2.6.9 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/undefsafe/node_modules/debug
       ms@2.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/undefsafe/node_modules/ms
       update-notifier@2.5.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/update-notifier
       boxen@1.3.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/boxen
       ansi-align@2.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ansi-align
       string-width@2.1.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/string-width
       is-fullwidth-code-point@2.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-fullwidth-code-point
       strip-ansi@4.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/strip-ansi
       ansi-regex@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ansi-regex
       camelcase@4.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/camelcase
       chalk@2.4.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/chalk
       ansi-styles@3.2.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ansi-styles
       color-convert@1.9.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/color-convert
       color-name@1.1.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/color-name
       escape-string-regexp@1.0.5 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/escape-string-regexp
       cli-boxes@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/cli-boxes
       term-size@1.2.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/term-size
       execa@0.7.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/execa
       cross-spawn@5.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/cross-spawn
       lru-cache@4.1.5 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/lru-cache
       pseudomap@1.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/pseudomap
       yallist@2.1.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/yallist
       shebang-command@1.2.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/shebang-command
       shebang-regex@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/shebang-regex
       which@1.3.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/which
       isexe@2.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/isexe
       get-stream@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/get-stream
       is-stream@1.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-stream
       npm-run-path@2.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/npm-run-path
       path-key@2.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/path-key
       p-finally@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/p-finally
       signal-exit@3.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/signal-exit
       strip-eof@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/strip-eof
       widest-line@2.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/widest-line
       configstore@3.1.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/configstore
       dot-prop@4.2.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/dot-prop
       is-obj@1.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-obj
       graceful-fs@4.2.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/graceful-fs
       make-dir@1.3.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/make-dir
       pify@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/pify
       unique-string@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/unique-string
       crypto-random-string@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/crypto-random-string
       write-file-atomic@2.4.3 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/write-file-atomic
       imurmurhash@0.1.4 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/imurmurhash
       xdg-basedir@3.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/xdg-basedir
       import-lazy@2.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/import-lazy
       is-ci@1.2.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-ci
       ci-info@1.6.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ci-info
       is-installed-globally@0.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-installed-globally
       global-dirs@0.1.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/global-dirs
       ini@1.3.5 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/ini
       is-path-inside@1.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-path-inside
       path-is-inside@1.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/path-is-inside
       is-npm@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-npm
       latest-version@3.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/latest-version
       package-json@4.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/package-json
       got@6.7.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/got
       create-error-class@3.0.2 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/create-error-class
       capture-stack-trace@1.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/capture-stack-trace
       duplexer3@0.1.4 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/duplexer3
       is-redirect@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-redirect
       is-retry-allowed@1.2.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/is-retry-allowed
       lowercase-keys@1.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/lowercase-keys
       safe-buffer@5.2.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/safe-buffer
       timed-out@4.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/timed-out
       unzip-response@2.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/unzip-response
       url-parse-lax@1.0.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/url-parse-lax
       prepend-http@1.0.4 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/prepend-http
       registry-auth-token@3.4.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/registry-auth-token
       rc@1.2.8 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/rc
       deep-extend@0.6.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/deep-extend
       minimist@1.2.5 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/minimist
       strip-json-comments@2.0.1 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/strip-json-comments
       registry-url@3.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/registry-url
       semver-diff@2.1.0 /tmp/build_317d5dd76ef85bfe907569c7873779e8/node_modules/semver-diff
       Installing any new modules (package.json)
       audited 159 packages in 1.2s

       1 package is looking for funding
         run `npm fund` for details

       found 0 vulnerabilities


-----> Build

-----> Caching build
       - node_modules

-----> Pruning devDependencies
       audited 159 packages in 1.077s

       1 package is looking for funding
         run `npm fund` for details

       found 0 vulnerabilities


-----> Build succeeded!
-----> Discovering process types
       Procfile declares types     -> (none)
       Default types for buildpack -> web
-----> Compressing...
       Done: 23M
-----> Launching...
       Released v8
       https://super-discord-bot23.herokuapp.com/ deployed to Heroku

存储库:https://github.com/yoavstrugo/Super-Bot.git

【问题讨论】:

好像build好的,run日志在哪里? 我认为没有。它只是没有运行 为了让我们能够为您提供帮助,您需要提供应用服务器日志,因为有崩溃的原因。您会通过$ heroku logs -a super-discord-bot23 获得运行时日志您的应用程序很可能在启动时崩溃,构建日志与此处无关。 【参考方案1】:

您无需在 Heroku 上打开应用程序。如果web dyno 被禁用,worker 被启用,那么一切都应该很好。检查您的机器人是否在 Discord 上在线。

不要点击这里:

检查它们是否在正确的位置:

【讨论】:

以上是关于在 Heroku 上托管 discord.js 机器人的主要内容,如果未能解决你的问题,请参考以下文章

Discord.js bot 没有上线由 Heroku 托管

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

故障上托管的不和谐机器人错误:找不到模块'discord.js'

Heroku discord bot 不断重启

如何在heroku中托管一个不和谐的机器人(错误)

在 Heroku 上托管 MusicBot