Best Discord Bot For Moderation

Test this app for free
762
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

Best Discord Bot For Moderation

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

Welcome to the step-by-step guide on how to use the Discord Moderation Bot template on Lazy. This template provides a pre-built Discord bot that monitors messages for profanity. When it detects inappropriate language, it automatically deletes the message and notifies the channel and the host. This guide will walk you through the process of setting up and deploying this bot on your Discord server.

Clicking Start with this Template

To begin, click on the "Start with this Template" button. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy or paste any code manually.

Initial setup: Adding Environment Secrets

Before testing the bot, you need to set up two environment secrets within the Lazy Builder:

  • DISCORD_BOT_TOKEN: This is the token you receive from the Discord Developer Portal when you create a new bot. It allows the bot to connect to the Discord API.
  • DISCORD_HOST_ID: This is the Discord user ID of the host who will receive notifications about deleted messages. You can find your user ID by enabling Developer Mode in Discord, right-clicking your username, and selecting "Copy ID".

To add these secrets, navigate to the Environment Secrets tab within the Lazy Builder and enter the respective values for each secret.

Test: Pressing the Test Button

Once you have set up the environment secrets, press the "Test" button. This will begin the deployment of the bot and launch the Lazy CLI. The bot will start running on the Lazy platform without the need for any local setup.

Using the App

After deployment, your Discord Moderation Bot will be active on your server. It will monitor messages in real-time and delete any that contain profanity. When a message is deleted, the bot will send a warning to the channel and notify the host via a direct message.

Integrating the App

To integrate the bot into your Discord server, you need to invite the bot to your server using the link provided by the Discord Developer Portal where you created your bot. Make sure to grant the bot the necessary permissions, such as "Manage Messages", to allow it to delete messages and function properly.

Remember to keep the bot's token and your user ID confidential to ensure the security of your bot and server.

By following these steps, you will have successfully set up and deployed the Discord Moderation Bot using the Lazy platform. Enjoy a cleaner and more professional environment on your Discord server!

Technologies

Discord Discord