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?
            Asked
            
        
        
            Active
            
        
            Viewed 2,049 times
        
    0
            
            
        - 
                    string has "indexOf" which returns the index if exist and -1 if not – Jafar Jabr Jan 10 '22 at 20:51
- 
                    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes – UnholySheep Jan 10 '22 at 20:52
- 
                    Please add the code where you read and process the discord message to your question. – kevintechie Jan 10 '22 at 21:02
- 
                    https://stackoverflow.com/questions/1789945/how-to-check-whether-a-string-contains-a-substring-in-javascript – epascarello Jan 10 '22 at 21:19
- 
                    https://stackoverflow.com/questions/5388429/javascript-jquery-how-to-check-if-a-string-contain-specific-words – epascarello Jan 10 '22 at 21:19
1 Answers
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
