Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我在Heroku Git上托管了一个discord.py机器人,即使我在网站上打开了它,它也不会在discord服务器上联机_Python_Python 3.x_Heroku_Discord.py - Fatal编程技术网

Python 我在Heroku Git上托管了一个discord.py机器人,即使我在网站上打开了它,它也不会在discord服务器上联机

Python 我在Heroku Git上托管了一个discord.py机器人,即使我在网站上打开了它,它也不会在discord服务器上联机,python,python-3.x,heroku,discord.py,Python,Python 3.x,Heroku,Discord.py,我的代码是,我的主要问题是,当我打开Heroku中的worker时,它不会在discord中在线。我知道这似乎是重复的,但其他问题的答案对我来说并不适用 import discord, os, time from dotenv import load_dotenv from discord.ext import tasks, commands TOKEN = 'xxxxxxxxxxxxxxxxxxxx' client = discord.Client() @client.event a

我的代码是,我的主要问题是,当我打开Heroku中的worker时,它不会在discord中在线。我知道这似乎是重复的,但其他问题的答案对我来说并不适用

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

OP在其
requirements.txt
中缺少导入。Heroku日志在确定错误原因方面非常有用。如果您正在使用Heroku CLI,您可以使用
Heroku日志检查日志,或者您也可以通过单击应用程序>更多>查看日志来检查网站上的日志。

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