0

I'm trying to make a simple discord bot. How can I make it so it checks for a word inside a message? For example if somebody says "i love bananas" and the trigger word is banana, the bot responds with "same". All I could figure out is how to make it reply to a specific message (like only "banana"), how do I make something like the example I made?

1 Answers1

1

discord.js v13.5.1

const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

const triggerWords = ['banana', 'fire', 'white'];

client.on('messageCreate', (message) => {
  if (message.author.bot) return false;

  triggerWords.forEach((word) => {
    if (message.content.includes(word)) {
      message.reply(message.content);
    }
  });
});

https://discord.js.org/#/docs/discord.js/stable/class/Client?scrollTo=e-messageCreate

amlxv
  • 1,610
  • 1
  • 11
  • 18