Answer the question
In order to leave comments, you need to log in
Anti-drain system, why doesn't the code work?
I'm trying to make it so that when a moderator assigns a certain role, the bot displays an error about the drain, and does not issue the role or take it away. In short, the anti-draining system. I tried to do it through client.event , but something doesn't work for me.
All this happens when issuing a role through a plus sign in the discord itself. Here is part of this code, but it throws an error:
line 111 ,'member_descriptor' object has no attribute 'role'
@client.event
async def on_member_update(before,after):
member = discord.Member
roles = discord.Role
#spectator_role = member.guild.get_role(748241633669152878)
#sp = member.guild.get_role(748241633669152878)
if [i.id for i in before.roles].count(728009097169076334):
if [i.id for i in after.roles].count(748241633669152878):
for guild in client.guilds:
channel = client.get_channel(724253008447143946)
await channel.send('ошибка')
role = discord.utils.get(member.guild.role, name="✨Spectator™✨") #line 111
await member.remove_roles(role)
return
Answer the question
In order to leave comments, you need to log in
Why did you do
member = discord.Member
?
All roles of a person are in
after.roles
If you need to block a certain role, you must first get it, then use for to view a new list of roles for a person, and if there is one you need among them, delete it
for role in after.roles:
if role.mention == bad_role:
await member.remove_roles(bad_role)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question