V
V
varmiloff2021-05-02 15:11:52
Python
varmiloff, 2021-05-02 15:11:52

How to make an anti-drain Discord system?

Hello. I want to make an anti-drain system for my Discord bot. So that when a certain role is assigned by some user, it is removed. I wrote some code, but anyway, when I give out a role, it is not removed. There is no error in the console.
Here is the code:

#anti sliv system
@client.event
async def on_member_update(before,after):
  bad_role = discord.utils.get(client.guild.roles, id =742695680635568139)
  member = after.roles
  roles = discord.Role
  for role in after.roles:
    if role.mention == bad_role:
        await member.remove_roles(bad_role)
        await member.remove_roles(role)
        return

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Deleting Account, 2021-05-02
@varmiloff

if role.mention == bad_role:
role.mention
``` Returns a string that allows you to mention the member. ```
I think the problem is in the condition. Instead of iterating, it's better to make a condition

guild_roles_ids = [role.id for role in guild.roles]
if role.id in guild_roles_ids: ...

That and the condition itself is better to take out in a separate function.
And what does a bad role "bad_role" do? I think it's better to name something like forbidden_role, not_allowed_role, role_ with_restrict_access

I
Isma009, 2022-03-02
@Isma009

What is this bot? How to add it to DS?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question