我正在寻找一种方法来向一组用户发送私人消息,这些用户具有相同的角色(使用discord.js)
我找到了发送消息(client.users.get(“ID”).send(“message”))的方法;但没有找到让列表中所有具有相同角色和循环的成员发送私人消息的方法。有人能帮我吗?
发布于 2019-05-23 04:40:08
您可以这样做:首先创建具有所需角色的所有成员的列表(参见Collection.filter()
),然后遍历(参见Map.forEach()
)并向每个成员发送DM。请查看下面的代码以获取示例。
// 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.
});
https://stackoverflow.com/questions/56263758
复制相似问题