Reputation: 95
Here I am again needing some help! So I'm coding a discord bot using JS, and I wanted to make a command that makes the user get temporary access to a channel, I know how to do that by adding roles, but my objective here it's to add only a user overwriting, not a entire role perm in the channel. This is the code that I use for now, but I want to change it to a user perm overwrite
var role = msg.guild.roles.cache.find(role => role.name === "Exclusive")
msg.member.roles.add(role)
setTimeout(() => {
msg.member.roles.remove(role)
})
Any help will be apreciated!
Upvotes: 0
Views: 274
Reputation: 547
To set a permission overwrite for a user, simply use GuildChannel#updateOverwrite.
It supports both users and roles.
For example:
var channel = message.guild.channels.cache.get('desired-channel-id');
await channel.updateOverwrite(message.author, {
VIEW_CHANNEL: true
});
This will grant the user access to the desired channel.
To deny the user the permissions, just turn true
into false
.
Hope this helps.
Upvotes: 1