The diskord bot bans those who are forbidden to ban

The bot discord bans those who can not be baned, I set the variable "a" to the value "user" and then output it:

Code:

@bot.command()
async def ban(ctx, user: discord.User):
    a = user
    print (a)
    if a == "никнейм#0000":
        await ctx.send(f'пользователь в белом списке')
    else:     
        await ctx.guild.ban(user)
        await ctx.send(f'пользователь {user}/{user.mention} был забанен')

The user who was mentioned was removed (not the id, but the nickname itself, which I thought was strange), but when I wrote the condition that if a = = "nickname" is not banned, the user was still sent to the ban...

Author: Jack_oS, 2021-01-12

1 answers

Better use the ID. This makes it much easier to write code, but it will be more difficult to understand.

if a.id == {whitelisted_id}:
    return await ctx.send("User in whitelist!")
else:
    #do your expensive stuff here

Note that the ID is an integer, not a string.

 2
Author: towerty, 2021-01-12 14:53:21