【问题标题】:Sending private message to a group of user (Discord.js)向一组用户发送私人消息(Discord.js)
【发布时间】:2019-10-09 08:26:14
【问题描述】:

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

我找到了发送消息的方法(client.users.get("ID").send("Message"); 但不是让所有具有相同角色的成员并在该列表上循环以向他们发送私人消息的方法。有人可以帮助我吗?

【问题讨论】:

标签: discord.js


【解决方案1】:

您可以这样做,首先列出所有具有所需角色的成员(请参阅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.
});

【讨论】:

    猜你喜欢
    • 2017-06-04
    • 2020-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    相关资源
    最近更新 更多