Matik
Matik

Reputation: 29

Private message to user

How to make a bot be able to send a private message to a specific person? (using user ID)

no, message.author is not what I need!

I'm using discord.js and node.js

Upvotes: 0

Views: 59

Answers (3)

Irian3x3
Irian3x3

Reputation: 56

This can be done with the User.send() method.

Here's an example of how it can be done by fetching the user

Make sure this is an async function, or the await will return an error.

const user = await <client>.users.fetch("USER ID"); // Replace <client> with your client variable (usually client or bot)

user.send("Message to send");

Upvotes: 1

Ahsoka
Ahsoka

Reputation: 184

Make sure this code is inside of an async function

// Getting the user object
const user = await <Client>.users.fetch('userID');

if (user) user.send('message').catch(error => {
    // code if error occurs
});

Upvotes: 1

pipebits
pipebits

Reputation: 26

client.users.fetch('123456789').then((user) => {
    user.send("My Message");
});

Dont forget replace "123456789" with the user id :D

Upvotes: 1

Related Questions