A Discord slash-command dice roller with true randomness (at least on the first roll).
-
Roll dice using the format:
AdB[kX][tY][+N|-N...]!DescriptionWhere:
A– number of diceB– number of sides per diekX– (optional) keep dice ≥ X; lower results are crossed out and don’t count toward the sumtY– (optional) target value; each kept die ≥ Y counts as a success+N/-N– (optional) integer modifiers applied to the final total!Description– (optional) text description of the roll
-
Uses RANDOM.ORG for the first die in each roll (true randomness), then falls back to Python’s
randomfor the rest. -
Logs each roll invocation with timestamp in PST time.
-
Works as a Discord slash command:
/roll.
- Python 3.10+ (recommended)
- A Discord bot application (with a bot token)
- A RANDOM.ORG API key
- The packages listed in
requirements.txt
Place the provided Python file dylanGPT.py and requirements.txt together in a folder.
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS / Linux
source .venv/bin/activateFrom the project directory:
pip install -r requirements.txtThe bot expects you to create a .env file yourself in the same directory as the Python script.
Create a file named .env with the following contents:
DISCORD_API_KEY=your_discord_bot_token_here
RANDORG_API_KEY=your_random_org_api_key_here-
DISCORD_API_KEY
- Go to the Discord Developer Portal.
- Create (or select) an application.
- Add a Bot to the application.
- Copy the Bot Token and paste it as
DISCORD_API_KEY.
-
RANDORG_API_KEY
- Go to RANDOM.ORG and create a free account.
- Navigate to the API section.
- Generate an API key and paste it as
RANDORG_API_KEY.
In the Discord Developer Portal:
- Go to OAuth2 → URL Generator.
- Check the scopes:
botapplications.commands
- Under Bot Permissions, give it at least:
Send Messages
- Copy the generated URL and open it in your browser to invite the bot to your server.
From the project directory:
python dylanGPT.pyYou should see the bot start up in the console. The first time it runs, it will sync the slash command tree.
-
num_diceis capped at 100:num_dice = 100 if num_dice > 100 else num_dice
-
sidesis capped at 2^31 - 1:sides = 2**31-1 if sides > 2**31-1 else sides
-
The first die in each roll attempts to use true randomness via RANDOM.ORG:
- If the API call fails, the bot logs this and falls back to
random.random().
- If the API call fails, the bot logs this and falls back to
-
Timestamps in logs are localized to America/Los_Angeles using
pytz.
-
Change the timezone by editing:
PST = pytz.timezone('America/Los_Angeles')
-
Adjust caps on dice count or sides.
-
Tweak the response formatting for your own style or embed-based output.
-
Expand the parser to support multiple dice expressions (e.g.
1d4+2d6-3).