Brian Zhou
Brian Zhou

Reputation: 1

How to overwritePermissions for voice channel?

For my parent category, the perms are set to everyone cannot connect to channels created and I want it so when someone reacts to the ✅, the bot allows anyone to join the voice channel. The code creates no errors but the permissions do not change. Does anyone know why?

Here is my code:

if(reaction.emoji.name === '✅') {
                    message.channel.overwritePermissions([
                        {
                           id: message.channel.guild.roles.everyone, 
                           allow: ['CONNECT'],
                           
                        },
                    ]);
                      
                }

Upvotes: 0

Views: 874

Answers (1)

Itamar S
Itamar S

Reputation: 1565

In order to update the '@everyone' role's permission overwrites, you will instead need to use message.guild.id

In addition to this, you're currently attempting to update the overwrites of a text channel to give connect permissions to everyone in the server which, let's be honest, does not really make much sense. If you're trying to execute this command while the executor is present inside of a voice channel, here's what I'd suggest:

  • First of all, you're able to pass the user argument in your reactions collector, therefore you could simply use const member = reaction.guild.member(user.id) to get the GuildMember object of the reactor.
  • After the bot has found the GuildMember object, you can simply use the member.voice.channel function to get the channel object of the executor

And finally, after all of the above has been done, your code should look like this:

const member = reaction.guild.member(user.id)
    const channel = member.voice.channel
    channel.overwritePermissions([
        {
            id: message.guild.id,
            allow: ['CONNECT']
        }
    ])

Upvotes: 1

Related Questions