如何覆盖 TextChannel 权限 [英] How to overwrite TextChannel permissions

查看:28
本文介绍了如何覆盖 TextChannel 权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Node.js 编写了一个 Discord Bot,我想用我的 bot 代码为玩家分配权限

I have code a Discord Bot, with Node.js, and I want, with the code of my bot, assign a permission for a player

为了解释更多细节,我尝试创建棋盘游戏狼人",与我的朋友在 Discord 上玩.我开发了这个机器人(使用 node.js ;我是初学者),当我在 Discord 上输入命令时,允许向玩家发送消息,说明他在游戏中的角色.

For explain a little more details, I try to create the board game "Werewolves", for playing with my friend on Discord. I develloped this bot (with node.js ; I'm a beginner), allowing, when I enter a command on Discord, to send a message to a player for saying his role in the game.

但是我现在阻止了一些事情:例如对于狼人"的玩家,我想给她一个频道的访问权限,以便他们可以一起交谈,而其他玩家无法查看消息(我可以用角色"来做到这一点,但是当有人检查另一个玩家的角色时,他可以查看他的角色;我认为没有什么可以看不到玩家的角色)

But I'm blocking in something now : for example for players who are "Werewolves", I want to give her an access to a channel, so that they can talk together, and the others players can't view the messages (I can make that with "roles", but when somebody check the role of an another player, he can view his role ; eand I don't think there is something to don't see roles of a player)

我检查了库 discord.js,并查看了两个解决方案;但我不能让两者都工作!第一个:(常量lg"代表狼人;法语中的 loup-garou ^^)

I have check the library discord.js, and I view two solutions ; but I can't get both to work ! The first : (the constant "lg" is for Werewolves ; loup-garou in french ^^)

 .then(function(member) {
     let lg = new Discord.Permissions(member, 0x00000400)
 })

第二个解决方案":

.overwritePermissions(guild.member {
    'VIEW_CHANNEL': true 
    'SEND_MESSAGES': true 
    'READ_MESSAGE_HISTORY': true
})

我重复一遍,但我已经在上面解释过;我试图得到,玩家有一个新的角色"(但这不是我想添加给他的角色)的事实,为他分配权限,因为他可以看到一个特殊的频道(如果是 Werewolf-channel他是游戏中的狼人),他可以在同一个频道上发送消息

I repeat, but I have already explained above; I'm trying to get, the fact that the player has a new "role" (but that is not a role I want to add to him), to assign him the permissions for he can see a special channel (Werewolf-channel if he's a werewolf in the game), and he can send a message on that same channel

这是一个屏幕(https://prnt.sc/k5qvvb):带有箭头,它是用户应该有他的名字的地方(这里例如是我的帐户^^),黄色是他应该拥有的权限(显然不需要将其他人置于假")

Here is a screen (https://prnt.sc/k5qvvb): with the arrow, it is the place where the user should have his name (here for example it's my account ^^), and in yellow the permissions he should have (putting others in "false" is obviously not required)

我没有收到任何错误,控制台没有显示任何异常......但是机器人没有做我想要的^^

I get no error, the console doesn't show anything abnormal... But the bot doesn't do what I want ^^

感谢您的帮助 :)奥克兹尔

Thanks for your help :) Oxzir

PS : 我是法国人,如果我的英语不太好,请见谅^^

PS : i'm french, so sorry if my english isn't sooo good ^^

推荐答案

您的第二次尝试是正确的,但是您将 guild.member 作为用户传递,但这不是 GuildMember(它是 undefined).因为,该属性不存在.
尝试传递 UserResolvable 类型对象:<Message>.author, <Message>.member.

Your second try is correct, but you're passing guild.member as the user, but that's not a GuildMember (it's undefined). Because, that property doesn't exists.
Try passing a UserResolvable type object: <Message>.author, <Message>.member.

message.guild.channels.find('name', 'loups-garous')
.overwritePermissions(UserResolvable, { // Pass 'UserResolvable' type thing as described in Wiki!
  VIEW_CHANNEL: true,
  SEND_MESSAGES: true,
  READ_MESSAGE_HISTORY: true,
  ATTACH_FILES: false
});

这篇关于如何覆盖 TextChannel 权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆