Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
31
rated 0 times [  32] [ 1]  / answers: 1 / hits: 14564  / 4 Years ago, thu, september 10, 2020, 12:00:00

I'm trying to make my discord.js bot send a message when it is pinged. I was unsure how to do this so I referred to this code:


client.on('message', message => {
if (message.content === '<@745648345216712825>') {
message.channel.send('Message Here');
}
});

However, this doesn't work.


Also, is it possible that my bot responds when a person mentions a specific user for example if I am mentioned by the user anywhere in a message the bot responds? If yes, can you show me how to do it?


More From » node.js

 Answers
6

Message has a property called mentions, which contains all the channels, members, roles, and users mentioned in the message. You can use the method .has(data, [options]) of MessageMentions to see if your bot was mentioned.




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

if (message.content.includes("@here") || message.content.includes("@everyone") || message.type == "REPLY") return false;

if (message.mentions.has(client.user.id)) {
message.channel.send("Hello there!");
}
});

The message event has been renamed to messageCreate in Discord.JS v13. Using message will still work, but you'll receive a deprecation warning until you switch over.


[#2710] Friday, September 4, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alejandro

Total Points: 231
Total Questions: 102
Total Answers: 107

Location: Jordan
Member since Wed, Jun 17, 2020
4 Years ago
;