如何在 EJS/DJS 中拉取所有成员服务器?

时间:2021-07-19 05:40:01

标签: node.js express discord.js ejs

在我的 discord bots 仪表板中,我希望拉出成员所在的所有服务器,以便我可以让成员管理这些服务器,但是,我尝试过的每件事都拒绝工作,我不再知道该怎么做在这里做。代码如下:

user.guilds.forEach(guild => {
    //const permsOnGuild = guild.permissions;
    //if(!user.guild.hasPermission('MANAGE_GUILD')) return;
    if(!guild.members.cache.get(user.id).hasPermission('MANAGE_GUILD')) return;

// Do a ton here for the servers.
)}

我继续收到的错误: 关于我尝试运行的实际代码段,它无法获取用户,无法读取未定义的缓存,无法读取我所做的任何事情甚至不起作用,它很久以前就起作用了(有点结束我第一次尝试开发仪表板时的 6 个月)。如果有人可以提供帮助,那就太棒了。

1 个答案:

答案 0 :(得分:1)

我不确定您要什么,但我想您是想检查是否有任何成员在服务器中管理公会。

var guild = message.guild; // You can change this
guild.members.fetch() // Fetches members first to avoid gateway intent problems
guild.members.cache.forEach(member=>{
  if(!member.hasPermission('MANAGE_GUILD')) return;
  // Do anything here as you like!
})

希望这有帮助。