Get the permissions of a category Channel and set it to voice channel discord.py

Viewed 930

I want to mute everybody in a voice channel changing the permission to speak, but when I do this it no sync with the category channel anymore.

cat = ctx.guild.get_channel(categorychannel)
everyone = ctx.guild.default_role
channel = await ctx.guild.create_voice_channel("test", category=cat)
await channel.set_permissions(everyone, speak=False)

So I'm trying to get the category channel permissions and set it to a voice channel, But for some reason it's not working.

cat = ctx.guild.get_channel(categorychannel)
everyone = ctx.guild.default_role
perm = cat.overwrites_for(everyone)
perm.speak = False
channel = await ctx.guild.create_voice_channel("test", category=cat)
await channel.set_permissions(everyone, overwrite=perm)

Can anyone help me?

2 Answers

The voice channel will not be in sync with the category because the permissions are not the same. So when you overwrite the speak permission with speak = False then it is no longer in sync with the category. If you sync permissions afterward you will overwrite the speak = False.

The second code you provided works as intended (as long as a category is found), it gets the permissions of the category, sets category permissions to the voice channel, sets speak = False, and then is no longer in sync with the category.

Trying to get it to work I moved the Bot file to my server and it's started working normally, I don't know why but it has, maybe the cache or some configs on my desktop. So the second code is right as @Lemon.py said. Here is the code.

cat = ctx.guild.get_channel(categorychannel)
everyone = ctx.guild.default_role
perm = cat.overwrites_for(everyone)
perm.speak = False
channel = await ctx.guild.create_voice_channel("test", category=cat)
await channel.set_permissions(everyone, overwrite=perm)

Thanks.

Related