【问题标题】:Issue with discord.py and heroku hostingdiscord.py 和 heroku 托管问题
【发布时间】:2020-09-05 09:52:07
【问题描述】:

美好的一天,我正在使用 discord.py 在空闲时间制作一个不和谐机器人。我最近添加了一个命令,允许我从特定位置获取 .txt 文件,并将该文件的内容作为消息发送到不和谐聊天中。在我的桌面上,这很好用。但是当我将它上传到 github 然后将分支部署到 heroku 进行托管时,.txt 突然不再被读取。我看不到任何错误代码。但我认为它给出了“找不到文件”的错误。

   async def chelp(self, ctx, name = 'help'):
        name = name.lower()
        file = open(f'cogs/chelp/{name}.txt', 'r')
        message = file.read()
        await ctx.send(message.format(ctx.author.name))
        await ctx.message.delete()

运行日志文件

2020-05-19T12:23:25.719698+00:00 heroku[worker.1]: Restarting
2020-05-19T12:23:25.791450+00:00 heroku[worker.1]: State changed from up to starting
2020-05-19T12:23:32.796643+00:00 heroku[worker.1]: State changed from starting to up
2020-05-19T12:23:35.896952+00:00 app[worker.1]: Failed to load extension cogs.ErrorHandler.
2020-05-19T12:23:35.896970+00:00 app[worker.1]: Extension 'cogs.ErrorHandler' could not be loaded.
2020-05-19T12:23:35.899274+00:00 app[worker.1]: Failed to load extension cogs.CustomCommands.
2020-05-19T12:23:35.899310+00:00 app[worker.1]: Extension 'cogs.CustomCommands' could not be loaded.
2020-05-19T12:23:39.000000+00:00 app[api]: Build succeeded
2020-05-19T12:23:40.768514+00:00 app[worker.1]: Tekxit Bot#3667 has connected to Discord!
2020-05-19T12:23:40.768567+00:00 app[worker.1]: Username is Tekxit Bot
2020-05-19T12:23:40.768568+00:00 app[worker.1]: ID is 463770605699989515
2020-05-19T12:23:40.768569+00:00 app[worker.1]: Keep this window open to keep the bot running.

【问题讨论】:

  • 这听起来可能很愚蠢,但是您是否检查过文本文件是否已上传?
  • 我检查了 git 页面,一切都在那里并且完成了。由于部署设置为使用 git 页面,它会自动复制粘贴我选择的整个分支,我无法在 Heroku 上查看文件结构。在这种情况下不存在愚蠢的问题。最好排除简单的错误,而不是搜索几个小时而没有找到任何东西。
  • 顺便说一句,您可以检查部署日志...试试这个:devcenter.heroku.com/articles/logging 我认为在做某事之前了解正在发生的事情会有所帮助
  • @SwetankPoddar 感谢您的建议。我现在意识到它不会加载 2 个齿轮。作为错误处理程序和文件阅读器。我在原始帖子中添加了日志。
  • 你能展示你的整个剧本吗?我有一种强烈的感觉,cogs 错误与您在此处显示的代码部分无关

标签: python heroku discord.py-rewrite


【解决方案1】:

我设法自己解决了这个问题。显然,我的 PC 上的 git 文件和本地文件之间存在差异。在齿轮也无法在我的笔记本电脑上加载后,我发现了这一点。显然,在失败的 2 个齿轮中,齿轮名称的大写与我在主桌面上设置的不同。希望这对任何偶然发现此问题的人有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2020-07-20
    • 2013-05-13
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多