Discord.js:如何使bot DM成为服务器中的所有成员?

时间:2020-07-09 09:09:06

标签: node.js discord discord.js

我希望我的机器人对服务器中的所有成员进行DM管理,但是我不知道如何执行此操作。如果可以的话,我将不胜感激!

Discord.js v12

1 个答案:

答案 0 :(得分:1)

message.guild.members.cache.forEach(member => { // Looping through each member of the guild.
    // Trying to send a message to the member.
    // This method might fail because of the member's privacy settings, so we're using .catch
    member.send("Hello, this is my message!").catch(e => console.error(`Couldn't DM member ${member.user.tag}`));
});