最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to make a discord js bot send directprivate message not to author? - Stack Overflow

programmeradmin1浏览0评论

I am using node.js for discord.

After I make a mand, I want my bot to send a direct/private message to a specific person, not the author who makes the mand (me).

Right now I have the person's <@000000000000000000> (I think this is called an ID), which is in String format.

For instance, this code client.sendMessage(message.author, "Hello!"); sends the author the message Hello. But I want one like client.sendMessage(message.user("<@000000000000000000>"), "Hello!");

Does a function like that exist?

For background information, I'm making a werewolf game bot where players are randomly assigned a role, and after I mand w!play I want the players to receive their roles in the DM.

I am using node.js for discord.

After I make a mand, I want my bot to send a direct/private message to a specific person, not the author who makes the mand (me).

Right now I have the person's <@000000000000000000> (I think this is called an ID), which is in String format.

For instance, this code client.sendMessage(message.author, "Hello!"); sends the author the message Hello. But I want one like client.sendMessage(message.user("<@000000000000000000>"), "Hello!");

Does a function like that exist?

For background information, I'm making a werewolf game bot where players are randomly assigned a role, and after I mand w!play I want the players to receive their roles in the DM.

Share Improve this question edited Aug 5, 2017 at 20:38 ricola asked Aug 5, 2017 at 17:54 ricolaricola 612 silver badges9 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

Yes just get the user object and send to that. You will need their id, so parse out the id part of the string "<@0000>". Also, sendMessage is deprecated. Use channel.send(). In the case of a user:

let str = "<@123456789>"; //Just assuming some random tag.

//removing any sign of < @ ! >... 
//the exclamation symbol es if the user has a nickname on the server.
let id = str.replace(/[<@!>]/g, '');

client.fetchUser(id)
    .then(user => {user.send("Hello I dmed you!")})

I would not write it that way unless you have a reason for doing so specifically.

I have used webhooks with git for discord, used hashtags to municate on a private channel, (and create dm channels) thus I can add in rules for deletion/exclusions (for admins or otherwise)

(This wouldn't be applicable to Facebook if you need Facebook integration)

发布评论

评论列表(0)

  1. 暂无评论