I'm using the discord.js library and node.js to create a Discord bot that facilitates poker. It is functional except the hands are shown to everyone, and I need to loop through the players and send them a DM with their hand.
bot.on("message", message => { message.channel.sendMessage("string"); });
This is the code that sends a message to the channel when any user sends a message. I need the bot to reply in a private channel; I've seen dmChannel
, but I do not understand how to use it. I have the username of the member that I want to send a message to. An example would be appreciated.
Edit: After looking around for a user object, I found that I can get all of the users using the .users
property of the client (bot). I will try using the user.sendMessage("string")
method soon.
If you want to DM the user who sent the interaction, you can use interaction. user. send() .
To access the DM window, Click the Home icon, which is your portrait on the upper left. This will show you a list of your friends, and the direct messages that you currently have. Clicking on the portrait of a friend will open the Direct Message window.
In order for a bot to send a message, you need <client>.send()
, the client
is where the bot will send a message to(A channel, everywhere in the server, or a PM). Since you want the bot to PM a certain user, you can use message.author
as your client
. (you can replace author
as mentioned user in a message or something, etc)
Hence, the answer is: message.author.send("Your message here.")
I recommend looking up the Discord.js documentation about a certain object's properties whenever you get stuck, you might find a particular function that may serve as your solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With