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

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

问题描述

我已经用Node.js编写了一个Discord 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

为解释更多细节,我尝试创建棋盘游戏"Werewolves",以便与我的朋友在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
})

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

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 ):带有箭头,是用户应使用其名字的位置(例如,这是我的帐户^^),黄色时应具有用户应具有的权限(显然不需要其他人输入"false")

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 (它是 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天全站免登陆