"ModuleNotFoundError: No module named 'discord' When Deploying Discord Bot on Railway"
tayyab-ai
FREEOP

4 months ago

Hello Railway Team,

I am facing a persistent deployment error with my Discord bot where the logs show:

text

ModuleNotFoundError: No module named 'discord'

Here are the key details:

  • My project includes a requirements.txt with:

    text

    py-cord==2.3.2 flask werkzeug gunicorn

  • The requirements.txt is at the root of my repository.

  • I have a Procfile with worker: python main.py.

  • Locally, the bot installs dependencies and runs perfectly.

  • However, Railway deployment logs do not show any installation of the Discord-related dependencies.

  • The build uses the Railpack system but seems to skip installing my Python dependencies, leading to this module error.

  • I’ve tried cache clearing and redeploying without success.

Could you please guide me on how to ensure Railway installs the Discord package (py-cord) properly during build? Is there a special config or file Railway expects for dependency installs?

Thank you for your help!

Deploy logs in my case:
2025-09-13T18:25:16.000000000Z [inf] Starting Container 2025-09-13T18:25:16.574749232Z [err] Traceback (most recent call last): 2025-09-13T18:25:16.574753762Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:16.574758644Z [err] import discord 2025-09-13T18:25:16.574763812Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:17.758810638Z [err] Traceback (most recent call last): 2025-09-13T18:25:17.758819630Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:17.758827328Z [err] import discord 2025-09-13T18:25:17.758834501Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:19.271197892Z [err] Traceback (most recent call last): 2025-09-13T18:25:19.271207580Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:19.271214177Z [err] import discord 2025-09-13T18:25:19.271220430Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:21.014067085Z [err] Traceback (most recent call last): 2025-09-13T18:25:21.014076246Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:21.014083001Z [err] import discord 2025-09-13T18:25:21.014090081Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:22.483340748Z [err] Traceback (most recent call last): 2025-09-13T18:25:22.483346308Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:22.483357250Z [err] import discord 2025-09-13T18:25:22.483362521Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:23.926805719Z [err] Traceback (most recent call last): 2025-09-13T18:25:23.926811579Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:23.926818348Z [err] import discord 2025-09-13T18:25:23.926825063Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:25.200395163Z [err] Traceback (most recent call last): 2025-09-13T18:25:25.200399699Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:25.200403206Z [err] import discord 2025-09-13T18:25:25.200406975Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:26.728724874Z [err] Traceback (most recent call last): 2025-09-13T18:25:26.728733904Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:26.728740713Z [err] import discord 2025-09-13T18:25:26.728746766Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:28.194739784Z [err] Traceback (most recent call last): 2025-09-13T18:25:28.194743755Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:28.194748365Z [err] import discord 2025-09-13T18:25:28.194752899Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:29.645766470Z [err] Traceback (most recent call last): 2025-09-13T18:25:29.645776946Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:29.645784768Z [err] import discord 2025-09-13T18:25:29.645792148Z [err] ModuleNotFoundError: No module named 'discord' 2025-09-13T18:25:31.124233001Z [err] Traceback (most recent call last): 2025-09-13T18:25:31.124240245Z [err] File "/app/main.py", line 7, in <module> 2025-09-13T18:25:31.124245869Z [err] import discord 2025-09-13T18:25:31.124251746Z [err] ModuleNotFoundError: No module named 'discord'

Github repo link in my case:
https://github.com/tayyab-ai/DFD_D.git

$10 Bounty

3 Replies


Apologies but this looks like an issue with the application level code. Due to volume, we can only answer platform level issues.


Status changed to Awaiting User Response Railway 4 months ago


brody
EMPLOYEE

4 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open brody 4 months ago


Since your main.py runs both Flask and Discord bot, change your Procfile to:
web: python main.py


Loading...