首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >向一组用户发送私人消息(Discord.js)

向一组用户发送私人消息(Discord.js)
EN

Stack Overflow用户
提问于 2019-05-23 03:32:57
回答 1查看 520关注 0票数 0

我正在寻找一种方法来向一组用户发送私人消息,这些用户具有相同的角色(使用discord.js)

我找到了发送消息(client.users.get(“ID”).send(“message”))的方法;但没有找到让列表中所有具有相同角色和循环的成员发送私人消息的方法。有人能帮我吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-23 04:40:08

您可以这样做:首先创建具有所需角色的所有成员的列表(参见Collection.filter()),然后遍历(参见Map.forEach())并向每个成员发送DM。请查看下面的代码以获取示例。

代码语言:javascript
复制
// Assuming 'guild' is defined as the guild with the desired members.

const roleID = ''; // Insert ID of role.
const members = guild.members.filter(m => m.roles.has(roleID) && m.user.id !== client.user.id);

members.forEach(member => {
  member.send('Hello there.')
    .catch(() => console.error(`Unable to send DM to ${member.user.tag}.`));
    // The above error would most likely be due to the user's privacy settings within the guild.
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56263758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档