Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to DM user using discord.js

I'm making a bot on Discord.js. The bot will give a role to every user. The problem is I want the bot DM the role to each user. The code was just not working for me.

What I've tried:

client.users.get('id').send('Blabla'), but it didn't work.

message.author.send("Blabla.") would only send the message to the author.

message.channel.send("Blabla") would only send the message to a channel.

like image 677
Christopher Kurniawan Avatar asked Mar 03 '23 14:03

Christopher Kurniawan


1 Answers

client.users.get('id').send('Blabla') did not work because in discord.js v12 you have to use the new cache system, in your case it's UserManager#cache.

So your solution is: client.users.cache.get('id').send('Blabla')

like image 53
Syntle Avatar answered Mar 05 '23 14:03

Syntle