Discord Moderation Bot

Test this app for free
30
import os
import discord
from discord.ext import commands
from better_profanity import profanity
import logging
import asyncio

bot_token = os.environ['DISCORD_BOT_TOKEN']
host_id = os.environ['DISCORD_HOST_ID']

bot_prefix = '!'

intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
intents.guilds = True
intents.dm_messages = True

bot = commands.Bot(command_prefix=bot_prefix, intents=intents)

# Set up logging to output to console instead of a file due to permission issues
logging.basicConfig(level=logging.INFO, format='%(asctime)s:%(levelname)s:%(name)s: %(message)s')
logger = logging.getLogger('discord')
Get full code

Frequently Asked Questions

How can this Discord Moderation Bot improve community management in my server?

The Discord Moderation Bot enhances community management by automatically monitoring and filtering out profanity in real-time. This helps maintain a family-friendly environment without constant manual moderation. The bot's ability to send warnings and notify the host about deletions ensures transparency and allows for quick follow-up actions if needed.

Can this bot be customized for different levels of moderation strictness?

While the current implementation of the Discord Moderation Bot uses a predefined profanity filter, it can be customized to suit different moderation needs. You could modify the profanity detection logic to include custom words or phrases, or even integrate with more advanced content moderation APIs for more nuanced filtering.

How does this bot contribute to maintaining a positive server culture?

The Discord Moderation Bot contributes to a positive server culture by consistently enforcing language guidelines. By promptly removing inappropriate content and issuing warnings, it sets clear expectations for user behavior. This proactive approach helps create a welcoming atmosphere for all members and reduces the likelihood of conflicts arising from offensive language.

How can I add custom commands to the Discord Moderation Bot?

You can add custom commands to the Discord Moderation Bot by using the @bot.command() decorator. Here's an example of how to add a simple ping command:

python @bot.command() async def ping(ctx): await ctx.send('Pong! Bot latency is {0:.2f}ms'.format(bot.latency * 1000))

Add this code to the main.py file, and users will be able to use the !ping command to check the bot's latency.

How can I modify the Discord Moderation Bot to log deleted messages to a specific channel instead of DMing the host?

You can modify the bot to log deleted messages to a specific channel by replacing the DM logic with a channel send. Here's how you can do it:

```python # Add this at the top of your file with other imports from discord.utils import get

# Replace the host DM logic in the on_message event with this log_channel_id = 123456789 # Replace with your log channel ID log_channel = get(message.guild.channels, id=log_channel_id) if log_channel: await log_channel.send(f'Action taken: Deleted a message from {message.author} in {message.channel} for profanity. The original message was: "{message.content}"') logger.info(f'Logged deleted message to channel {log_channel.name}') else: logger.warning('Log channel not found.') ```

This modification will send the deletion log to a specified channel instead of DMing the host, allowing for easier tracking and review of moderation actions.

Created: | Last Updated:

The Discord bot monitors all messages in the server. If a message contains profanity, the bot deletes it and sends a warning to the channel. The bot also notifies the host about the deletion via a direct message. Additionally, the bot outputs a helpful error message to a channel if there is a permissions error, guiding the server admin to enable the required permission in the Discord Developer portal.

Introduction to the Discord Moderation Bot Template

The Discord Moderation Bot template helps you create a bot that monitors all messages in a Discord server. If a message contains profanity, the bot deletes it and sends a warning to the channel. Additionally, the bot notifies the host about the deletion via a direct message and outputs a helpful error message to a channel if there is a permissions error.

Clicking Start with this Template

To get started with the Discord Moderation Bot template, click the "Start with this Template" button.

Test

Press the "Test" button to begin the deployment of the app. The Lazy CLI will appear, and you will be prompted for any required user input.

Entering Input

The code requires two environment secrets to be set up: - `DISCORD_BOT_TOKEN`: This is the token for your Discord bot. You can get this from the Discord Developer Portal. - `DISCORD_HOST_ID`: This is the user ID of the host who will receive notifications about deleted messages.

To set up these environment secrets: 1. Go to the Environment Secrets tab within the Lazy Builder. 2. Add a new secret for `DISCORD_BOT_TOKEN` and paste your bot token. 3. Add another secret for `DISCORD_HOST_ID` and paste the user ID of the host.

Using the App

Once the bot is deployed and running, it will automatically start monitoring messages in your Discord server. If a message contains profanity, the bot will: - Delete the message. - Send a warning to the channel. - Notify the host about the deletion via a direct message.

Integrating the App

To integrate the bot into your Discord server: 1. Go to the Discord Developer Portal and create a new application. 2. Add a bot to your application and copy the bot token. 3. Set the bot token as the `DISCORD_BOT_TOKEN` environment secret in the Lazy Builder. 4. Invite the bot to your Discord server using the OAuth2 URL Generator in the Discord Developer Portal. Ensure you give the bot the necessary permissions, including "Manage Messages".

By following these steps, your Discord Moderation Bot will be up and running, helping to keep your server free from profanity and notifying the host about any actions taken.



Here are 5 key business benefits for this Discord Moderation Bot template:

Template Benefits

  1. Automated Content Moderation: The bot automatically filters out profanity, reducing the workload on human moderators and maintaining a family-friendly environment in business-related Discord servers.

  2. Improved Brand Protection: By swiftly removing inappropriate content, the bot helps protect a company's brand image and reputation in their online communities.

  3. Enhanced User Experience: The bot creates a more positive and professional atmosphere for users, which can lead to increased engagement and retention in business-focused Discord channels.

  4. Compliance and Risk Management: For businesses in regulated industries, the bot helps maintain compliance with content guidelines and reduces the risk of legal issues related to user-generated content.

  5. Actionable Insights: The bot's logging and reporting features provide valuable data on moderation actions, helping businesses understand community behavior and refine their moderation strategies over time.

Technologies

Discord Automation & Bots Discord Automation & Bots

Similar templates

We found some blogs you might like...