Discord.js:如何让机器人 DM 成为服务器中的所有成员?

Posted

技术标签:

【中文标题】Discord.js:如何让机器人 DM 成为服务器中的所有成员?【英文标题】:Discord.js : How to make a bot DM all members in a server? 【发布时间】:2020-10-29 20:12:24 【问题描述】:

我希望我的机器人 DM 我服务器中的所有成员,但我不知道如何去做。如果您能提供帮助,我将不胜感激!

Discord.js v12

【问题讨论】:

【参考方案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`));
);

【讨论】:

以上是关于Discord.js:如何让机器人 DM 成为服务器中的所有成员?的主要内容,如果未能解决你的问题,请参考以下文章