Reputation: 29
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
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
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
Reputation: 26
client.users.fetch('123456789').then((user) => {
user.send("My Message");
});
Dont forget replace "123456789"
with the user id :D
Upvotes: 1