用于worker的Heroku Procfile:python

2024-10-04 03:27:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图将discord.py bot推送到Heroku,但在Procfile中遇到了一些错误。我的机器人由COG组成,它们位于不同的文件夹中,但我不知道如何在Procfile中指定目录。我在一些答案中读到,使用/有效,但对我的案例不起作用。首先,我的项目是这样的:

---- cogs
-------- BuiltInCogs.py
-------- Some other cogs that aren't really relevent
Procfile
community_bot.py

我的proc文件如下所示:

worker: python community bot.py 
worker: python cogs/BuiltInCogs.py

请注意,第一行有效,但对于第二行,我得到以下错误:

2020-10-08T18:09:52.975127+00:00 heroku[worker.1]: State changed from crashed to starting
2020-10-08T18:09:58.753154+00:00 heroku[worker.1]: Starting process with command `python cogs/BuiltInCogs.py`
2020-10-08T18:09:59.594842+00:00 heroku[worker.1]: State changed from starting to up
2020-10-08T18:10:01.790915+00:00 app[worker.1]: python: can't open file 'cogs/BuiltInCogs.py': [Errno 2] No such file or directory
2020-10-08T18:10:01.908250+00:00 heroku[worker.1]: Process exited with status 2
2020-10-08T18:10:01.983906+00:00 heroku[worker.1]: State changed from up to crashed

Tags: tofrompycommunityherokubot错误worker
1条回答
网友
1楼 · 发布于 2024-10-04 03:27:41

如果bot.py是您的主起始文件,那么您的COG应该已经被这样调用:

extensions = ['cogs.firstCog', 'cogs.secondCog']
if __name__ ==  "__main__":
    for ext in extensions:
        client.load_extension(ext)

您的Procfile只需要包含bot的主文件:)

相关问题 更多 >