最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to create a discord.js lock command - Stack Overflow

programmeradmin0浏览0评论

I'm trying to create a lock and unlock mand for my discord.js bot. 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.

Then if I do >unlock, it unlocks the channel.

I'm trying to create a lock and unlock mand for my discord.js bot. 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.

Then if I do >unlock, it unlocks the channel.

Share Improve this question edited May 27, 2020 at 8:25 Peyman Mohamadpour 18k24 gold badges92 silver badges101 bronze badges asked May 26, 2020 at 19:07 SP73SP73 4157 silver badges18 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

In your function, you just need to call the following lines to remove the permissions,

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

role.permissions.remove('SEND_MESSAGES')

and to give them back, just put the following lines under the mand:

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}**")
发布评论

评论列表(0)

  1. 暂无评论