Gwubby
Gwubby
DIAdiscord.js - Imagine an app
Created by Gwubby on 1/15/2024 in #djs-questions
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;
}
}
});
8 replies