JohnnyBot is a Discord moderation bot designed to automate role management and enforce server rules. It provides features such as automatic role assignment, message deletion, and user management to ensure a smooth server experience.
-
Automatic Role Management:
- Assigns the "bad bots" role to new members automatically.
- Removes the "bad bots" role from members who complete onboarding.
-
Moderation Automation:
- Deletes messages sent by members with the "bad bots" role in non-DM channels.
- Kicks members with the "bad bots" role who violate server guidelines.
- Bans members with the "bad bots" role or no role who DM the bot, deleting their messages across the server.
-
Forum Management:
- Automatically replies to new threads in the "🧑💻・job_postings" forum with a required message
-
Command-based Moderation:
- Provides moderators with slash commands to manage members, messages, and post announcements.
-
Logging and Notifications:
- Logs actions and errors to a rotating log file.
- Sends notifications to a designated moderators-only channel.
-
Message Archive:
- Allows moderators to dump and archive user messages from specific channels
- Provides temporary download links for message archives
- Automatically cleans up old archive files
-
Pet Interactions:
- Includes JohnnyBot functionality with time-based messages
/pet
command to interact with JohnnyBot
- Python 3.7 or higher
- Official Discord.py library version 2.4 or higher
- Flask 2.0.0 or higher (for message dump web server)
- Waitress 2.1.2 or higher (for production-ready web server)
Note the bot uses both asyncio and threading for different purposes. DON'T CHANGE THIS:
-
asyncio is used for:
- All Discord API interactions (primary event loop)
- Background tasks (like reminder checking)
- Command handling
- Network operations
-
threading is used for:
- Synchronous operations that can't be made async (like file I/O)
- Thread-safe caching of Discord objects
- Synchronization primitives (locks) for shared resources
This hybrid approach allows the bot to:
- Handle Discord's async API efficiently
- Perform blocking operations without stalling the event loop
- Maintain thread safety for shared resources
- Scale well under load
-
Clone the repository:
git clone https://github.com/yourusername/johnnybot.git
-
Install the required dependencies:
pip install -r requirements.txt
-
Configure the bot settings:
- Open the
bot.py
file in a text editor. - Modify the following constants according to your server's setup:
BAD_BOT_ROLE_NAME
: Role assigned to bad bots (default: 'bad bots').MODERATOR_ROLE_NAME
: Moderator role name (default: 'Moderators').DELAY_MINUTES
: Delay before assigning the "bad bots" role to new members (default: 4 minutes).LOG_FILE
: Name of the log file (default: 'johnnybot.log').MODERATORS_CHANNEL_NAME
: Name of the moderators channel for notifications (default: 'moderators_only').
- Open the
- Ensure all installation steps are complete.
- Add your Discord bot token to an environment variable called
DISCORD_BOT_TOKEN
- Run the bot:
python bot.py
- The bot should now be online and moderating your Discord server.
Description: Sets a reminder message to be sent to a specified channel at regular intervals.
- Parameters:
channel
: The target channel.title
: Title of the reminder.message
: The reminder content.interval
: Interval (in seconds) between reminders.
Description: Lists all current reminders.
Description: Deletes all active reminders.
Description: Deletes a reminder by title.
- Parameters:
title
: Title of the reminder to delete.
Description: Deletes a specified number of messages from a channel.
- Parameters:
channel
: The channel to purge messages from.limit
: Number of messages to delete.
Description: Deletes all messages containing a specific string from a channel.
- Parameters:
channel
: The channel to purge messages from.search_string
: String to search for in messages.
Description: Deletes all messages sent by webhooks or apps from a channel.
- Parameters:
channel
: The channel to purge messages from.
Description: Kicks a member from the server.
- Parameters:
member
: Member to kick.reason
: Reason for the kick (optional).
Description: Makes the bot send a message to a specified channel.
- Parameters:
channel
: Target channel.message
: Message to send.
Description: Timeouts a member for a specified duration.
- Parameters:
member
: Member to timeout.duration
: Timeout duration in seconds.reason
: Reason for the timeout (optional).
Description: Sends the last specified number of lines from the bot's log file to the user via DM.
- Parameters:
lines
: Number of lines to retrieve.
Description: Adds a calendar feed URL to check for events.
- Parameters:
calendar_url
: URL of the calendar feed.channel_name
: Channel to post notifications (default: bot-trap).
Description: Adds a calendar feed to check for events.
- Parameters:
calendar_url
: URL of the calendar feed.
Description: Lists all registered calendar feeds.
Description: Removes a calendar feed.
- Parameters:
feed_url
: URL of the calendar feed to remove.
Description: Check on JohnnyBot.
Description: Pet JohnnyBot.
Description: See who JohnnyBot prefers today.
- Parameters:
user1
: First potential favorite.user2
: Second potential favorite.
Description: Dumps a user's messages from a specified channel into a downloadable file. Compresses the file and hosts it via a temporary web server for 30 minutes.
-
Parameters:
user
: User whose messages to dump.channel
: Channel to dump messages from.start_date
: Start date in YYYY-MM-DD format (e.g., 2025-01-01).limit
: Maximum number of messages to fetch (default: 1000).
-
Features:
- Retrieves messages with proper pagination
- Handles Discord API rate limits
- Automatically cleans up orphaned dump files
- Provides a download link via DM
- Link expires after 30 minutes
- The bot automatically manages roles and moderates the server based on the configured rules.
- Moderators can perform actions using the slash commands listed above.
- Log files are accessible, and the bot can DM logs on request through the
/log_tail
command.
Contributions are welcome! If you encounter any bugs or have suggestions, feel free to open an issue or submit a pull request.
Cat functionality adapted from PetBot under MIT License.
This project is licensed under the GNU General Public License v3.0.