Reputation:
I want to make it so when I run a command it DMs a certain person, how can I do that?
Upvotes: 0
Views: 57
Reputation: 251
There is a little white space in your question there. If you aren't asking what Lioness100 said, I am sure you mean: "DM a person when this command runs".
This is simple to do, but there are rules,
If all of the above applies then you are good to go.
First, get the user. I am assuming the user will be called in the arguments (e.g. ;kick ${user}), if there aren't any mentions, get the user from cache.
const user = message.mentions.members.first()
|| message.guild.members.cache.get(args[0]); // <-- replace with your argument index.
user.send("Your text here") // <-- will be sent to the user in DM's, embeds are allowed.
Wait! What if the user is not in the server?
Well, we can simply do an if
statement (also, if you are trying to implement a system where you can DM a person with their ID, use bot.users.cache.get(args[0])
, or a database)
// Before DMing user
if (!user) return message.channel.send('Sorry! That user cannot be found!')
// Feel free to add permissions to run this command!
Hoped this helped, Stay safe.
Upvotes: 1
Reputation: 8402
You can use:
if (message.author.id !== '<Put your user ID here>') return;
Upvotes: 0