Skip to content

Setup CodeGrind Bot Locally

Kevin Roman edited this page Jul 16, 2025 · 11 revisions

Getting Started

To set up a testing version of the bot, you need to follow the steps ahead:

Initial Setup

  1. Create a Discord application: Visit Discord developers applications and create an application.

  2. Add bot: Substitute <YOUR_BOT_CLIENT_ID> with your application's client id in the link below and press the link to add it to your selected server.

Make sure to also select all the 'Privileged Gateway Intents' on the Bot page.
https://discord.com/oauth2/authorize?client_id=<YOUR_BOT_CLIENT_ID>&scope=bot&permissions=8

Database Configuration

  1. Create a MongoDB database: Go to MongoDB, create a database, get the MongoDB URI (connection string), and add your IP address to the IP access list in the network access tab.

  2. Create a .env file: Within the project's root directory, create a .env file and add the environment variables given below. Replace <your_discord_bot_token> and <your_mongodb_uri> with your specific values.

    DISCORD_TOKEN=<your_discord_bot_token>
    MONGODB_URI=<your_mongodb_uri>
    TOPGG_TOKEN=null
    LOGGING_CHANNEL_ID=<the_channel_id_to_log_to>
    DEVELOPER_DISCORD_ID=<your_discord_account_id>
    PRODUCTION=False
    

Virtual Environment Setup

  1. Python version: Ensure Python version 3.11 or later is installed on your computer.

  2. Setup a virtual environment: Install the Python venv module and set up a virtual environment. Here are the instructions for setting up a Python's virtual environment.

Make sure to call your virtual environment either .venv or venv when creating it, so that it is correctly ignored and not added to your commits.

To activate the virtual environment, navigate to the directory where the virtual environment is located and run the following commands:

  • For Windows:

    .\env\Scripts\activate
    
  • For Unix or macOS:

    source env/bin/activate
    
  1. Install required libraries: With the virtual environment activated, install all the necessary libraries using the following pip commands:

    pip install -r requirements.txt
    python -m playwright install
    

Running the Bot

  1. Run the bot: With all the setup complete, run the following command (from the root directory of the project):

    python -m src.main
    

    The first time you run the bot, you will also need to write and send a message within a channel in the server your local bot is in that pings your bot and says "sync" (e.g. "@CodeGrind Bot sync") in order to sync and see all of your bot's commands. This only needs to be done when the bot is setup initially, or when new commands are implemented.

    After you've synced the commands, make sure to restart Discord.

    Whilst the program is running, you should now be able to execute bot commands on your server.