简体   繁体   English

如何找到具有特定权限的角色?

[英]How do I find a role with a specific permission?

So I'm trying to create a discord bot and one of the commands for the bot needs me to filter roles by the permissions they're allowed (or, at least this would be the easiest way), and I can't seem to figure out how to do that.所以我正在尝试创建一个 discord 机器人,机器人的其中一个命令需要我按允许的权限过滤角色(或者,至少这是最简单的方法),我似乎不能弄清楚如何做到这一点。 I've tried way too many things to even count, and at this point, I'm looking for a different way.我已经尝试了太多的东西,甚至数不清,在这一点上,我正在寻找一种不同的方式。 But if anyone has the answer to this, that would be amazing.但是,如果有人对此有答案,那将是惊人的。

Basically I wanna do this:基本上我想这样做:

let staff = message.channel.guild.roles.cache.filter(s => s has this permission)

(Pseudo-code obviously) (显然是伪代码)

But as I said, I just can't seem to figure it out.但正如我所说,我似乎无法弄清楚。

            case 'staff':
    
            let staff = chan.guild.roles.cache.filter(m => m.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES));

            
            //console.log(staff)

                message.guild.channels.create(Channel, 'text').then (
                    function() {
                        let ch = message.guild.channels.cache.find(ch=>ch.name === Channel)
                        ch.updateOverwrite(message.guild.id, { VIEW_CHANNEL : false });
                        ch.updateOverwrite(staff, { VIEW_CHANNEL : true })
                    }
                )
                type.stop()
            break;
    

Also, 'chan' is a shortened version of 'message.channel'此外,“chan”是“message.channel”的缩写版本

Is this what you're looking for?这是你要找的吗?

let rolesWithManageMessagesPermission = 
    message.channel.guild.roles.cache.filter(r => r.permissions.has(Permissions.FLAGS.MANAGE_MESSAGES)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM