From 66197c18f81d0a6180e7ead128b3a2daddb2e8e6 Mon Sep 17 00:00:00 2001 From: Elnath Date: Sat, 23 Jan 2021 18:14:23 +0100 Subject: [PATCH] Bugfix: on some server, the bot could not create channels because of category overwrites containing roles higher that its --- VocalMaisBot.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/VocalMaisBot.py b/VocalMaisBot.py index 9abe309..82c802c 100755 --- a/VocalMaisBot.py +++ b/VocalMaisBot.py @@ -236,11 +236,20 @@ class VocalMaisBot(commands.Cog): logger.debug(f"[{channel.guild.name}({channel.guild.id})] User {user.name}#{user.discriminator}({user.id}) connected to watched channel {channel.name}({channel.id})") # We create a channel for them and move them into it category = channel.category - # Creating the permissions of the channel - channel_permissions = category.overwrites # We base them on the category's permissions + + # Creating the permissions of the channel, based on the watched channel's category permissions. + # However, tests showed that discord forbids the bot from creating overwrites on roles that are higher than the bot in the list of roles + bot_highest_role_position = channel.guild.get_member(self.bot.user.id).top_role.position # The position of the highest role that the bot has + channel_permissions = {} + for subject, overwrite in category.overwrites.items(): + if isinstance(subject, discord.Role): # Overwrites can contain role overwrites and member overwrites + if subject.position >= bot_highest_role_position: # We ignore roles higher than the bot + continue + channel_permissions[subject] = overwrite + # We allow the user for which we created the channel to change the channel's name if user not in channel_permissions: channel_permissions[user] = discord.PermissionOverwrite() - channel_permissions[user].manage_channels = True # We allow the user for which we created the channel to change the channel's name + channel_permissions[user].manage_channels = True # Computing the channel name user_default_channel_name = self.channels_config.get_user_channel_name(channel.guild, user)