Is there a command to send private message to all

2019-09-20 12:40发布

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条回答
\"骚年 ilove
2楼-- · 2019-09-20 13:06

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 :)

查看更多
登录 后发表回答