【问题标题】:I am hosting a discord.py bot on Heroku Git and it wont go online on the discord server even though I turned it on in the website我在 Heroku Git 上托管了一个 discord.py 机器人,即使我在网站上打开了它,它也不会在 discord 服务器上上线
【发布时间】:2020-09-08 01:40:50
【问题描述】:

我的代码是,我的主要问题是,当我在 Heroku 中打开工作器时,它不和谐地不在线。我知道这可能看起来像重复,但其他问题的答案对我不起作用。 :

import discord, os, time
from dotenv import load_dotenv
from discord.ext import tasks, commands


TOKEN = 'xxxxxxxxxxxxxxxxxxxx'

client = discord.Client()


@client.event
async def on_ready():
    print(f"RoleCheck has connected to {client.guilds[0].name}")
    global channel
    channel = client.guilds[0].get_channel(xxxxxxxxxxxxxxxxxx)
@client.event
async def on_member_update(before, after):
    newRole = next(role for role in after.roles if role not in before.roles)
    if newRole.name == "1":
        print(f"IGN:{after.nick} \nDiscord:{after.name}")
        global msg
        msg = await channel.send(f"IGN:{after.nick} \nDiscord:{after.name}")

@client.event
async def on_message(message):
    if message.content.startswith("!comment"):
        _content = "Comment: " + msg.content + '\n' + message.content[8:]
        await msg.edit(content=_content)
    elif message.content.startswith("!help"):
        await channel.send("---RoleCheck--- \n!comment - will add a comment on the last message with whatever you write after\n !help = will show the help screen\n Made with python and the discord.py API by xxxxxxxx")
client.run(TOKEN)


Procflile:
worker: python bot.py

requirements.txt:
discord.py==1.4.1

【问题讨论】:

  • 日志说什么?如果您使用 Heroku CLI,请使用 heroku --logs
  • 查看日志后发现我有一个导入,但没有包含在我的 requirements.txt 中。这是我不再使用的旧导入,因此我将其删除(dotenv)。谢谢!将其发布为答案,我会检查它!
  • 很高兴你成功了,祝你好运。

标签: python python-3.x heroku discord.py


【解决方案1】:

OP 在其requirements.txt 中缺少导入。 Heroku 日志对于确定错误原因非常有帮助。如果您使用 Heroku CLI,您可以使用 heroku logs 查看您的日志,或者您可以在网站上点击您的应用 > 更多 > 查看日志来查看您的日志。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-28
    • 2019-02-14
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-22
    • 2016-12-31
    相关资源
    最近更新 更多