Is there a way to run a discord bot and django code through heroku?

Everything seems to work until i get to the build part on heroku,

-----> $ python manage.py collectstatic --noinput
       Starting up None shards...
       130 static files copied to '/tmp/build_a4988370/staticfiles', 8 unmodified, 361 post-processed.
       Connected to shard 0
       Shard 0 ready
-----> Timed out running buildpack Python
 !     Push failed

This is what happens
it runs the website code and it starts by bot (shard-ed bot), and then it wont continue the build and it just fails, does anyone have any ideas, here is some of my code

#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
import asyncio
from threading import Thread

def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)


if __name__ == '__main__':
    from discordbot.main import _main
    loop = asyncio.new_event_loop()
    loop.create_task(_main())
    Thread(target=loop.run_forever).start()
    

^manage.py

def main():
    """Run administrative tasks."""
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings.settings')
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)   

def _main():
   loadcogs()
   print("Starting up {} shard{}...".format(bot.shard_count,"" if bot.shard_count == 1 else "s"))
   
   main()
   thread = Thread(bot.run("mydiscordtoken"))
   thread.start()

^discordbot/main.py

I didnt really try anything specific because i have no idea how this could work

Back to Top