admin管理员组文章数量:1426953
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 badges2 Answers
Reset to default 2Yes 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)
本文标签: javascriptHow to make a discord js bot send directprivate message not to authorStack Overflow
版权声明:本文标题:javascript - How to make a discord js bot send directprivate message not to author? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745475912a2659961.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论