Ad S.S
Ad S.S

Reputation: 156

Discord JS, reply to certain user ID

I want to make a command where the bot will only reply to a certain user id. But I'm confused how to make it so (FYI I'm new on JS)

const userID = '<@4608164XXX93150209>'

bot.on("message", function(message){
if(!message.author === userID)
{

if(message.content === 'psst')
    {
        message.channel.send('Hello there!');
    }
}});

Upvotes: 0

Views: 30919

Answers (4)

aByteCurious
aByteCurious

Reputation: 66

A little late to reply, but I had the same question and I used msg.sender instead of msg.author

const userID = "4608164XXX93150209"

bot.on("message", function(message){
if(!message.sender === userID)
{

if(message.content === 'psst')
{
    message.channel.send('Hello there!');
}
}});

Note that msg.sender is a string and not numeric

Upvotes: 3

Harel
Harel

Reputation: 21

I see that that people wrote different answers here, so ill just write the specific code you should use.

const userID = "The_user's_id";

bot.on("message", function(message) {
    if (message.author.id === userID) {
        message.react('emoji name or id');
    }
});

Note: to find the id of a user, just right click him and press "copy ID".

Upvotes: 2

Farid Movsumov
Farid Movsumov

Reputation: 12725

You can fetch the author id of the message with the message.author.id and then apply your logic.

let authorId = message.author.id;
//check author id here...

let mentionString = '<@!'+authorId+'>';
message.channel.send(mentionString+' pong');

Upvotes: 0

kalen
kalen

Reputation: 21

That is just a string, not a guild member id. Here do this.

const userId = message.guild.members.find(m => m.id === "USER ID HERE");

Upvotes: 1

Related Questions