X
X
x4zx2021-07-21 22:18:29
Python
x4zx, 2021-07-21 22:18:29

How to remove a person from channel permissions in discord?

Hello, I am writing my discord bot and there are two commands `lockreport` and `unlockreport`, the first closes access to the channel for communication with admins, and the second opens it, the first command works fine, but with the second I don’t know what to do, I need to do so that when I type the second command, the bot removed the person from the channel rights, that is, when the first command is entered, the bot adds the participant to the channel and gives him rights, and in the case of the second command, it should be the other way around - the bot must remove the person from the channel.

Command code:

@bot.command()
@commands.has_role(833314249827680257)
async def lockreport(ctx, member: discord.Member = None):
    if member is None:
        emb6 = discord.Embed(title = '', description = f'{ctx.author.mention}, вкажіть кому ви хочете закрити доступ до <#858859193109184542>!', colour = 0xFF8C00)
        await ctx.send(embed = emb6)
    else:
        channel = bot.get_channel(858859193109184542)
        await channel.set_permissions(member, overwrite = discord.PermissionOverwrite(view_channel = False))
        emb7 = discord.Embed(title = '', description = f'{ctx.author.mention}, доступ до <#858859193109184542> для {member.mention} успішно закритий!', colour = 0xFF8C00)
        await ctx.send(embed = emb7)

@bot.command()
@commands.has_role(833314249827680257)
async def unlockreport(ctx, member: discord.Member = None):
    if member is None:
        emb8 = discord.Embed(title = '', description = f'{ctx.author.mention}, вкажіть кому ви хочете відкрити доступ до <#858859193109184542>!', colour = 0xFF8C00)
        await ctx.send(embed = emb8)
    else:
        channel = bot.get_channel(858859193109184542)
        await channel.set_permissions(member, overwrite = discord.PermissionOverwrite(view_channel = True))
        emb9 = discord.Embed(title = '', description = f'{ctx.author.mention}, доступ до <#858859193109184542> для {member.mention} успішно відкритий!', colour = 0xFF8C00)
        await ctx.send(embed = emb9)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question