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

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.

Technologies

Discord Discord
Python App Templates for Scraping, Machine Learning, Data Science and More Python App Templates for Scraping, Machine Learning, Data Science and More
Flask Flask