Lumap
Lumap

Reputation: 3

How to dm a user with a discord.js bot

I'm creating a discord bot using discord.js and I want to do a command like this one:

t!mp "text" user

The prefix is t!. The "text" is the message content and the user is at the end of the command. This commands just send a direct message to the tagged user. How can I recreate a command like this?

Upvotes: 0

Views: 1094

Answers (2)

Ethan Mitchell
Ethan Mitchell

Reputation: 602

client.users.find(t => t.id == "The Users ID").send("Your message");

Upvotes: 0

Saddy
Saddy

Reputation: 1581

To send a DM to a user, use

<Member>.send(“text”)

You can get the mentioned user from message.mentions.members.first()

For the text part, split message.content, select what you want with indexing, then .join(“ “)

Upvotes: 1

Related Questions