I was doing a badword "detector" and don't works when It is to send the console.log
the code:
const fs = require("fs");
// Función para detectar la palabra prohibida.
function detectForbiddenWord(content) {
const forbiddenWords = require("../../../forbidden-words.json");
for (const word of forbiddenWords) {
if (content.includes(word)) {
console.log(
Forbidden word detected: ${word}
);
// Realiza aquí la acción correspondiente para la palabra prohibida
// Por ejemplo, puedes aplicar una sanción al usuario o enviar un mensaje de advertencia
return true;
}
}
return false;
}
module.exports = {
name: "interactionCreate",
async execute(interaction, client) {
if (!interaction.isCommand()) return;
const { commandName } = interaction;
const command = client.commands.get(commandName);
if (!command) return;
try {
await command.execute(interaction);
// Verificar si la interacción es un mensaje
if (interaction.type === "MESSAGE") {
const content = interaction.content;
if (content && detectForbiddenWord(content.toLowerCase())) {
console.log("Message with forbidden word detected");
}
}
} catch (error) {
console.error(error);
if (!interaction.replied) {
await interaction.reply({
content: "Something went wrong while executing this command.",
ephemeral: true,
});
}
}
},
};5 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.Codeblocks:
```js
const Discord = require("discord.js");
// further code
```
becomes
Inline Code:
`console.log('inline!');` becomes
console.log('inline!');
What is
content
defined as? Doesn't look like it's in the message event
forbiddenWords
is an objectIf i'm getting this right, you're trying to make a filter for messages. But you do not have a messageCreate event, messages are not interactions
I dont even think message is a type and types also are enums in v14, not strings iirc
ok thanks I'll solve