Bugfix: on some server, the bot could not create channels because of category overwrites containing roles higher that its
This commit is contained in:
parent
66b733a94c
commit
66197c18f8
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue