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 badges2 Answers
Reset to default 2In 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}**")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745253967a4618843.html
评论列表(0条)