Start from the template
- Create a bot from the Moderation template and choose Python (discord.py).
- In Test, send a message containing
badwordas alex — it is deleted and a warning appears. - Switch Acting as to moddy and try again: moderators are exempt.
- Try
/kickas alex: the sandbox shows that members without Kick Members can't use it.
The core idea
Reading message text needs the privileged Message Content Intent. A minimal filter looks like this:
import os
import discord
BANNED = {"badword", "scamlink"}
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
@client.event
async def on_message(message: discord.Message):
if message.author.bot or message.guild is None:
return
if any(word in message.content.lower() for word in BANNED):
await message.delete()
await message.channel.send(f"{message.author.mention}, that word is not allowed here.")
client.run(os.environ["DISCORD_TOKEN"])Make it yours
Open AI edit and ask, for example: “Add the words spam and scam to the banned list and time people out for 5 minutes instead of warning them.” Review the change before applying it.
Good practice
- Keep moderation commands restricted with required permissions.
- Log actions to a private
#mod-logchannel. - Remember that the bot can't moderate the server owner or members with a higher role.
Ready to build your first bot?
Create a bot — free