Is there a command to send private message to all members of a group?

梦想与她 提交于 2019-12-10 12:17:45

问题


Is there any way to make a command send a private message to all members of the discord group using discord.js?

Exemple: /private TEST

This message is sent to everyone in the group in private chat instead of channel chat.


回答1:


You can iterate through Guild.members.
When you receive a message that starts with /private, you take the rest and send it to every member of the guild by using Guild.members.forEach().
Here's a quick example:

client.on('message', msg => {
  if (msg.guild && msg.content.startsWith('/private')) {
    let text = msg.content.slice('/private'.length); // cuts off the /private part
    msg.guild.members.forEach(member => {
      if (member.id != client.user.id && !member.user.bot) member.send(text);
    });
  }
});

This is just a basic implementation, you can obviously use this concept with your command checks or modify that by adding additional text and so on.

Hope this solves the problem for you, let me know if you have any further questions :)



来源:https://stackoverflow.com/questions/51705319/is-there-a-command-to-send-private-message-to-all-members-of-a-group

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!