word filtering

Trying to get this word filter to work. Its logging "Checking message" and its running the for loop, but its not running the if statement nor am I getting the catch. I originally had the deprecated "message" instead of "messageCreate" and it was just deleting every message sent, but now its not deleting anything. It has the guild messages intent.
const badword = ['test'];

client.on('messageCreate', message => {
const content = message.content;
const stringToCheck = content.replace(/\s+/g, '').toLowerCase();

console.log('Checking message:', content);

for (let i = 0; i < badword.length; i++) {
console.log('test');
if (stringToCheck.includes(badword[i])) {
console.log('Bad word found. Deleting message:', content);
message.delete()
.then(deletedMessage => console.log('Message deleted:', deletedMessage.content))
.catch(error => console.error('Error deleting message:', error));
break;
}
}
});
const badword = ['test'];

client.on('messageCreate', message => {
const content = message.content;
const stringToCheck = content.replace(/\s+/g, '').toLowerCase();

console.log('Checking message:', content);

for (let i = 0; i < badword.length; i++) {
console.log('test');
if (stringToCheck.includes(badword[i])) {
console.log('Bad word found. Deleting message:', content);
message.delete()
.then(deletedMessage => console.log('Message deleted:', deletedMessage.content))
.catch(error => console.error('Error deleting message:', error));
break;
}
}
});
6 Replies
d.js toolkit
d.js toolkit12mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Gwubby
GwubbyOP12mo ago
node version 21.5.0
Ashish
Ashish12mo ago
Discord.JS version? And can you show me all your intent list?
Gwubby
GwubbyOP12mo ago
13.17.1
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
});
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
],
});
Toast
Toast12mo ago
add MESSAGE_CONTENT intent and see.
Gwubby
GwubbyOP12mo ago
dope that worked ty
Want results from more Discord servers?
Add your server