- Added /bank and /wallet commands to check user balances - Enhanced transfer validation to check for valid number input - Included debug token logging in main function (to be removed in production) - Added account creation logic for new users in balance commands - Improved error handling for invalid transfer amounts
Discord Bot Project
Overview
This is a versatile Discord bot project, built using discord.py. The bot includes:
- Admin Commands for moderating servers
- Economy System to manage virtual currency
- Fun Commands for interactive experiences
- Role Management to assign roles based on user actions or preferences
The bot is structured with scalability in mind, using cogs to separate different functionalities and utilities for common operations.
Features
- Admin Commands: Moderation tools such as banning and kicking members.
- Economy System: Tracks user balances and allows users to earn or spend virtual currency.
- Fun Commands: Simple commands that provide entertainment, such as games or random interactions.
- Role Management: Commands that automate role assignments for users.
Setup
1. Clone the Repository
Clone the repository to your local machine:
git clone https://github.com/yourusername/discord-bot.git
cd discord-bot
2. Install Requirements
Install the necessary Python packages listed in requirements.txt:
pip install -r requirements.txt
3. Set Up Environment Variables
The bot requires environment variables for configuration. Create a .env file in the root directory and add your Discord bot token:
DISCORD_TOKEN=your_token_here
4. Run the Bot
Run the bot using the command below:
python bot.py
Folder Structure
Here’s an outline of the directory and file structure for this project:
discord-bot/
│
├── bot.py
├── bot_development.py
├── main.py
├── dockerfile
├── requirements.txt
├── README.md
├── Fixes.md
│
├── cogs/
│ ├── admin.py
│ ├── customCommands.py
│ ├── economy.py
│ ├── gamble.py
│ ├── informational.py
│ ├── listeners.py
│ ├── mail.py
│ ├── npc.py
│ ├── xp.py
│
├── utils/
│ ├── bank_functions.py
│ ├── npc_data.py
│ ├── npc_handler.py
│ ├── npc_memory.py
│ ├── sql_commands.py
│
├── web/
│ ├── __init__.py
│ ├── app.py
│ ├── static/
│ ├── templates/
Usage
Commands
1. Admin Commands
!ban <member> <reason>: Bans a specified member from the server with an optional reason.!kick <member> <reason>: Kicks a specified member from the server with an optional reason.
2. Economy Commands
!balance: Check your current balance.!deposit <amount>: Deposit a specified amount to your bank.!withdraw <amount>: Withdraw a specified amount from your bank.
3. Fun Commands
!roll <number>: Rolls a random number up to the specified max.!8ball <question>: Provides a magic 8-ball response to your question.
4. Role Management Commands
!assignrole <role>: Assigns a role to a user.!removerole <role>: Removes a role from a user.
Notes
- All commands can be customized by modifying their respective cog files in
cogs/. - Admin commands require appropriate permissions (e.g., ban and kick require
Ban MembersorKick Memberspermissions).
Configuration
Permissions
Make sure your bot has the appropriate permissions for each command. You can manage permissions in the Discord Developer Portal, where you created your bot. Ensure that:
- The bot has
Administratorpermissions if needed. Intentssuch asMessage Content,Guild Presences, andGuild Membersare enabled as required by the bot.
Environment Variables
Store sensitive information like your bot token in the .env file. Avoid committing this file to version control.
Database
The bot currently uses MySQL for user and balance data through utils/sql_commands.py and utils/bank_functions.py. You can update these modules if you want to change the database engine or schema.
Contributing
Contributions are welcome! Here’s how you can contribute:
- Fork the project.
- Create a feature branch (
git checkout -b feature/AmazingFeature). - Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/AmazingFeature). - Open a pull request.
Make sure to include docstrings for any new functions and comments for complex logic to maintain readability.
License
No license file is included in this repository. Add a LICENSE file if you want to make the license explicit.
Contact
For support, please contact yourname@example.com.
Happy Coding!
Deployment (Web UI)
This project includes a small Flask-based web UI used for OAuth flows and guild management. The development server is fine for local testing, but for production use you should run the app under a WSGI server such as waitress or gunicorn.
Recommended steps to serve the web UI with waitress:
- Install dependencies (includes
waitress):
pip install -r requirements.txt
- Set the required environment variables (example
.env):
# Bot and web settings
TOKEN=your_bot_token_here
DISCORD_CLIENT_ID=your_client_id
DISCORD_CLIENT_SECRET=your_client_secret
DISCORD_REDIRECT_URI=https://yourdomain.com/callback
# Flask session secret (must be set in production)
SECRET_KEY=replace_with_a_secure_random_value
# Optional runtime
START_WEB=1 # set to 1 if you want the bot process to spawn the web UI
REQUEST_TIMEOUT=10 # default HTTP timeout in seconds for external requests
- Run the web app using
waitress(example):
python -m waitress --host=0.0.0.0 --port=5000 web.app:app
Notes:
- If you set
START_WEB=1,bot_development.pywill spawn the web UI when the bot starts. This is convenient for small deployments but consider running the web UI in its own process or container for reliability and easier scaling. - Never run the Flask development server (app.run) in production.
- Ensure
SECRET_KEYis kept secret and not committed to source control. Use a secure random value likeopenssl rand -hex 32.
If you want, I can add a small Procfile and Dockerfile snippet for deployment — tell me which target (Heroku, Docker Compose, or Kubernetes) you prefer.