如何使discord.js bot dm成为我服务器中的所有成员

时间:2019-05-24 20:52:54

标签: javascript discord.js

我正试图使我的机器人DM成为所有人(不仅仅是新成员),而且我不知道我将如何去做。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

// Async context (within async function), 'message' being the command message.

const members = message.guild.members.filter(m => !m.user.bot).array(); // Filter out bots.

let undelivered = 0;

for (let i = 0; i < members.length; i++) {  // Using an array and a for loop rather than
  const member = members[i];                // Collection.forEach() due to the fact that
  await member.send('Hello there.')         // the latter will move onto the proceeding
    .catch(() => undelivered++);            // code before waiting for the promises to
}                                           // fulfill. https://stackoverflow.com/a/37576787

message.channel.send(`Messages sent. ${undelivered} members couldn't receive it.`)
  .catch(console.error);