Discord.js v13 Detects Specific Messages

Asked 2 years ago, Updated 2 years ago, 115 views

** is hidden because of abusive language.
What code should I reply to when I find a sentence with a specific message?

client.on("messageCreate", (msg)=>{
    if(message.content.match==="**"){
        msg.reply("Don't abuse, slander, etc.");
    }
});

javascript node.js discord

2022-09-29 22:03

1 Answers

I don't know much about node.js (JavaScript) or discord.js myself, so I'm not very confident, but
The code in the question appears to be a mixture of comparison (===) and pattern match (match).

If you want to react to a containing the specified keyword, you will see the following:

Create multi-function bot with discord.js - Qiita

client.on('message',message=>{
  if(message.content.match(/write this word/)){
    message.channel.send('Send a message in here');
  }
});

Use === to react when the contents of the message match (exactly) with the specified keyword.

client.on('message',message=>{
    if(message.content==='Enter this word'){
        message.channel.send('React with this word');
   }
});


2022-09-29 22:03

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.