K
K
Kadabrov2020-07-23 16:10:53
Python
Kadabrov, 2020-07-23 16:10:53

How to restrict access to the channel to users with the same nicknames?

There is a function that automatically distributes roles to those who are on the list, using the role, users get access to a private voice channel

@bot.event
async def on_voice_state_update(member, before, after):
    clients = ['Dr','1','2']
    if not before.channel and after.channel:
        role = discord.utils.get(member.guild.roles, name="Клиент")
        if member.display_name in clients:
            await member.add_roles(role)
    elif before.channel and not after.channel:
        role = discord.utils.get(member.guild.roles, name="Клиент")
        await member.remove_roles(role)


A problem arises when a smart user gives himself the same nickname as a user with a role and gains access.
I tried to get a list of users of a private channel and check if there is one on the channel, then do not give it. I also tried to get the user ID, write it down and check it, but member does not have such an attribute as ID. I will be grateful for help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-07-23
@Kadabrov

discord.Member has an attributeid .

@bot.event
async def on_voice_state_update(member, before, after):
    clients = [969338428647912064, 424184503818564866, 424184503818564866]
    role = bot.get_role(240688302893711904)
    if not before.channel and after.channel:
        if member.id in clients:
            await member.add_roles(role)
    elif before.channel and not after.channel:
        await member.remove_roles(role)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question