简体   繁体   English

如何创建 discord.js 锁定命令

[英]How to create a discord.js lock command

I'm trying to create a lock and unlock command for my discord.js bot.我正在尝试为我的 discord.js 机器人创建锁定和解锁命令。 How would I be able to do this?我怎么能做到这一点?

I want to make it so when I do >lock it takes permission away from Verified to SEND_MESSAGES .我想这样做,所以当我执行 >lock 时,它会将权限从 Verified 转移到SEND_MESSAGES

Then if I do >unlock, it unlocks the channel.然后,如果我 >unlock,它会解锁频道。

In your function, you just need to call the following lines to remove the permissions,在您的 function 中,您只需调用以下行来删除权限,

const role = guild.roles.find("name", "Verified ");

role.permissions.remove('SEND_MESSAGES')

and to give them back, just put the following lines under the command:并将它们归还,只需将以下几行放在命令下:

const role = guild.roles.find("name", "Verified ");

role.permissions.add('SEND_MESSAGES')

If you want to understand why this will work, here are some relevant docs links: role , permissions , and the permissions flags .如果您想了解为什么这会起作用,这里有一些相关的文档链接:角色权限权限标志

EDIT: To change the permissions for the specific channels, just do:编辑:要更改特定频道的权限,只需执行以下操作:

const role = guild.roles.find("name", "Verified ");

message.channel.overwritePermissions(role,{ 'SEND_MESSAGES': false })

and to give them back, you would do the following并给他们回来,你会做以下

const role = guild.roles.find("name", "Verified ");

message.channel.overwritePermissions(role,{ 'SEND_MESSAGES': true})

I guess you need this我猜你需要这个

const role2 = message.guild.roles.cache.find(role => role.name === 'Member') 
message.channel.updateOverwrite(role2,{ 'SEND_MESSAGES': false}) 
message.channel.send("Successfully locked **${message.channel.name}**")

and this for unlock这用于解锁

const role = message.guild.roles.cache.find(role => role.name === 'Member') 
message.channel.updateOverwrite(role,{ 'SEND_MESSAGES': true})   
message.channel.send("Successfully unlocked **${message.channel.name}**")

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

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