Discord Bot That Deletes Messages

 import os
import discord
import asyncio
from datetime import datetime, timedelta, timezone
from discord.ext import commands, tasks
from collections import defaultdict

intents = discord.Intents.all()
intents.members = True

bot = commands.Bot(command_prefix='!', intents=intents)

channel_id = int(os.getenv('DISCORD_CHANNEL_ID'))  # The specific channel ID to clear
clear_interval_seconds = None  # No default clear interval

async def on_ready():
   print(f'Logged in as {bot.user.name}')
   if clear_interval_seconds is not None:

async def set_clear_interval(ctx, seconds: int):

About this template

The Discord Message Management Bot is designed to manage messages in a Discord channel. It requires two environment variables to function properly: DISCORD_BOT_TOKEN (the token of your Discord bot) and DISCORD_CHANNEL_ID (the ID of the channel where messages will be managed). The bot includes several commands that allow an admin to manage messages in the channel, including setting an automatic message clearing interval, removing the automatic message clearing interval, deleting all messages from a specific user, deleting all messages sent by a specified bot, deleting all duplicate messages, and deleting all messages containing a specific keyword.

Introduction to the Discord Bot That Deletes Messages Template

Welcome to the guide on how to use the Discord Bot That Deletes Messages template on Lazy. This template is designed to help you manage messages within a Discord channel by providing commands to set an automatic message clearing interval, remove the interval, delete messages from specific users or bots, remove duplicate messages, and delete messages containing a specific keyword. This bot is a powerful tool for Discord server administrators looking to keep their channels clean and organized.

Clicking Start with this Template

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

Initial Setup: Adding Environment Secrets

Before you can use the bot, you'll need to set up two environment secrets within the Lazy Builder:

  • DISCORD_BOT_TOKEN: This is the token of your Discord bot. You can obtain this token from the Discord Developer Portal where you created your bot.
  • DISCORD_CHANNEL_ID: This is the ID of the Discord channel where messages will be managed. You can find this by enabling Developer Mode in your Discord settings, right-clicking on the channel, and selecting "Copy ID".

Enter these values in the Environment Secrets tab within the Lazy Builder.

Test: Pressing the Test Button

Once you have set up the environment secrets, press the "Test" button to deploy the app. The Lazy CLI will launch, and the bot will start running on the Lazy platform.

Entering Input: Filling in User Input

If the bot requires any user input, you will be prompted to provide it through the Lazy CLI after pressing the test button. Follow the prompts to enter the necessary information.

Using the App

After deployment, you can use the bot commands directly within your Discord server. For example, you can type !set_clear_interval 3600 to set the message clearing interval to one hour. The bot will respond to commands issued by users with administrative rights in the Discord server.

Integrating the App

If you wish to integrate this bot with other tools or services, you may need to provide the bot's server link or API endpoints. Since this template is designed to work within Discord, no additional integration steps are required unless you want to extend the bot's functionality with external services.

Remember, all the commands and functionalities provided by this bot are to be used within the Discord platform. There is no need to integrate it with external tools unless your specific use case requires it.

By following these steps, you should now have a fully functional Discord bot that can manage messages in your channel. Enjoy your cleaner and more organized Discord server!

Last published
July 20, 2024

More templates like this

AlphaBot Financial Summary

AlphaBot Financial Summary: A Discord bot that utilizes the Alpha Vantage API to provide AI-generated summaries of income statements, balance sheets, and cash flow for renowned US companies.


Discord Moderation Bot

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.


Discord Bot

This powerful app skeleton is a great starting place for a Discord bot

Discord Bot That Deletes Messages