Discord.py Bot setup for Glitch

Hello! Ive recently been wanting to see about making a discord bot for my server. I already have all of the code setup and ready to go, i just need to make sure i’m not missing anything in my project and that as well that i can find a way to run this project via the IDE. I think i’ve got everything all setup and all i need todo is run the proiject but again i have no idea of how todo that so yeah. Thanks for the help in advance

Project Code

You will need to add a few files:


python bot.py


(place what you installed with pip here)

That should do the trick!

1 Like

It’s better to generate a requirements.txt file which you can do by running pip freeze > requirements.txt than listing your dependencies manually. The generated version will automatically include versions and the dependencies of your dependencies so you can guarantee the execution environment is the same as your development environment.

Also important to note that you probably want to be using python3 and pip3 instead because python refers to the old, deprecated, unsupported version of Python 2 installed on Glitch’s containers. In most cases you want modern Python 3 (which is also available on Glitch).

what does the start.sh do exactly? I didnt have to use that before

how exactly would i generate a requirements,.txt then with this error code?
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at Release process - pip documentation v21.0.dev0 pip 21.0 will remove support for this functionality.

As I said above, use pip3 instead:
pip3 freeze > requirements.txt
Note that you’ll have needed to have already installed your dependencies with pip3 install <module>

It’s one of the ways Glitch detects how to run your non-node project. Glitch looks for a package.json file when running Node apps. If it doesn’t find one it assumes the project is a static site unless it also finds either a start.sh script or a glitch.json file. To run a Python app you need to use one of those otherwise Glitch will serve your site statically. I’m personally a fan of glitch.json:

    "install": "pip3 install -r requirements.txt",
    "start": "python3 <file>"
1 Like

this should then run the entire file? when i do what essentially

It’ll run your file whenever your container is loaded, yes. I’m afraid I don’t understand the second part of your response.

1 Like

when i open up the project, would it automatically load the bot or do i have to do it manually, because what i want to be able todo is to run this all automatically when i open the project up

Edit: so far I have this all setup for my project, im now getting errors that discord and dotenv cannot be found when they should be there in the files

You will need to install those with pip like @FlantasticDan said.

they should then be installed when i open the project every-time then? I shouldunt have to rerun the command everytime i want to use it

If you’ve properly configured your requirements.txt and glitch.json as described above then yes.

In practice Glitch installs modules to the machine which is hosting the container that is your project (this is why there’s no site-packages folder in your project). From time to time your project may be moved to a new host that doesn’t have your dependencies installed, but with the properly configured install command, Glitch will detect this and install everything automatically in the background on startup.

So if all you did was manually install with pip3 then you’d see it working for some time but eventually find errors although you hadn’t changed any of your codebase.

Following proper configuration is good practice beyond Glitch. It allows collaborators to quickly and easily replicate your development environment, it allows you to deploy projects to other IaaS providers, and on larger projects it makes scaling much easier.

I still do not know how to work this out here, i have the glitch.json setup i think but i do not know why when i click on the project it will not run my code, i always have to manually run it using the terminal which i do not want todo at all. I want to have it all be automated when i click onto the project it will begin to run the bot. How can i make this possible and easily as well?

Could you link me your project?

its right here or what do you mean exactly

You have to follow the directions we gave you. I don’t see a glitch.json file nor a requirements.txt file.

Just added the glitch.json and requirements.txt. Id had some stuff in the glitch.json before but it was giving me errors so i removed it for right now, as for the requrements.txt i have no idea of what to put in there

I see you added the files, thats good.

Your requirements.txt should look like:


(99% sure os and random are built into python, but if anyone else knows more than python here than I do, please tell me if I’m wrong)

Your glitch.json file should look like:

  "install": "echo 'No install needed'",
  "start": "python bot.py"

@RiversideRocks os and random are a part of Python’s standard library and ship with Python.

However, as I’ve mentioned earlier in this thread, you want glitch.json to look like this:


and to that end you’d want

which can be done by

I’m fairly confident that my previous explanations in this thread are approachable and beginner friendly but if they’re not please ask whatever questions you may have. It feels a bit like the answers have been here the whole time yet have been ignored.


i think, and im 98% sure that its working properly but i think with all that said and done i think i got it working though i cant be too sure just yet though