【问题标题】:How do I find all members with a specific role on 'ready'? Discord.js如何在“就绪”时找到所有具有特定角色的成员?不和谐.js
【发布时间】:2021-06-19 08:57:19
【问题描述】:

我知道以前有人问过这个问题,但我还没有为最新版本的 Discord.JS 找到可靠的答案。我想查找公会 hostGuild 中所有具有“xyz”角色的成员。

client.on('ready', () => {
    const hostGuild = client.guilds.cache.get('822234110369595443');
    //get users with role 'xyz'
    }
});

【问题讨论】:

标签: javascript discord.js


【解决方案1】:

你试过.members.cache吗?它看起来像这样:

const membersWithRole = hostGuild.members.cache.filter(m => m.roles.cache.has('roleid'));

编辑:它似乎不起作用,因为成员和角色没有被缓存。您需要在这里使用 async/await:

const allMembers = await hostGuild.members.fetch();
const membersWithRole = allMembers.filter(m => m.roles.cache.has('roleid'));

【讨论】:

    猜你喜欢
    • 2020-10-24
    • 2018-10-22
    • 2020-12-05
    • 2020-11-22
    • 2020-08-20
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 2021-02-16
    相关资源
    最近更新 更多