D
D
Di2022-01-14 09:46:27
Python
Di, 2022-01-14 09:46:27

How to force the bot to check the personal rights of users (discord.py)?

I'm trying to get a bot to change the member limit of a voice channel, assuming the member has control of the channel

@client.command()
async def limit(ctx, arg): 
    channel5 = ctx.author.voice.channel
    perm = channel5.permissions_for(ctx.message.author)
    if perm == 'manage_channels':
        await channel5.edit (user_limit = arg)
        await ctx.send(f'Лимит участников изменен на {arg}')
    else:
        await ctx.send('У вас недостаточно прав для выполнения данной команды')

But when using the command, the bot gives out else in any case
. I clearly understand that the problem is most likely in this line: But I don’t know how to fix it, please help
if perm == 'manage_channels':

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-14
@Vindicar

Oh, how many wonderful discoveries the official documentation is preparing for us...
We look at GuildChannel.permissions_for() , we see

Return type: Permissions

Cry. Reading (emphasis mine):
Wraps up the Discord permission value.
The properties provided are two ways. You can set and retrieve individual bits using the properties as if they were regular bools . This allows you to edit permissions.

Those. an object of this class has the above properties, and a significant proportion of them are logical values ​​(bool). Do you need manage_channels ? Then the check should be done like this:if perm.manage_channels:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question