I built a Discord bot for my server and I want to add word filtering features to it. I’m trying to figure out how to detect inappropriate language and handle it automatically.
What I want to achieve:
When someone types: “You are stupid”
Bot changes it to: “You are [censored for inappropriate language]”
Is it actually possible to modify user messages in Discord? My bot has administrator privileges including message deletion rights, but I’m not sure if it can edit existing messages from users.
If message editing isn’t possible, can I make the bot delete the original message and post a warning instead?
Like: “Bot: @user Please watch your language!”
Here’s my current bot setup:
const discord = require('discord.js');
const bot = new discord.Client();
bot.on('ready', () => {
console.log('Bot is now active!');
});
bot.on('message', msg => {
if(msg.content === '!weather'){
msg.reply('Today is sunny and warm!');
}
if(msg.content === '!time'){
msg.reply('Current time is 3:00 PM!');
}
});
bot.login('YOUR_BOT_TOKEN_HERE');
you totally cant edit user messages on discord, even if ur an admin. deleting the msg and sending a warning is a solid idea! just make a list of banned words and check msg.content against it. if u find a match, use msg.delete() then send the warning. works well for me!
Discord’s API won’t let bots edit messages from other users - doesn’t matter what permissions you have. Delete-and-warn is your best bet. I built something like this using an array of filtered words with includes() to scan messages. When it catches something, I delete the message right away and DM the user explaining what they did wrong. Keeps the bad stuff off the channel while still letting them know they messed up. Just make sure you add error handling around the delete function - users sometimes delete their own messages before your bot gets to them.
Discord bots can’t edit messages - that’s baked into the API. But your delete-and-warn approach works great. Use regex patterns instead of basic string matching since users love bypassing filters (@ for a, 3 for e, etc). Something like /st[u@]p[i1]d/gi catches way more variations than just “stupid”. You might want a strike system too - repeat offenders get temp timeouts after multiple warnings. setTimeout() handles temporary role removal nicely. Watch out for rate limiting though - delete too many messages fast and Discord will throttle your bot.