Answer the question
In order to leave comments, you need to log in
Would like to track when a user loses the discord.py role?
I have a command that randomly defines a user once per hour and gives them a special role, and I want the user from that role to give others a role, and they have a kind of clan. But after a random person loses this role, namely in a day, I want the clan to be disbanded as well, namely those users who were given the role, at the end of the day, that is, when the bot itself removes the role for a random person, with With this he took off and others who were added.
@commands.cooldown(1, 3600, commands.BucketType.default)
async def pd(ctx):
gomo_role = discord.utils.get(ctx.guild.roles, id=800360472595267604)
alyanc_role = discord.utils.get(ctx.guild.roles, id=801182180101324810)
await ctx.send('```Итак гомо часа становиться...```')
await asyncio.sleep(float(0.5))
await ctx.send('```Барабанная дробь.....```')
await asyncio.sleep(float(0.5))
global user
user = choice(ctx.channel.guild.members)
if user == bot.user:
print('бот гей часа')
await ctx.send('```Увы но гомо часа стал я, альянс делать не буду,по этому просто давайте отдохнём```')
else:
await ctx.send(f'``Эта: ``{user.mention}')
await user.add_roles(gomo_role, alyanc_role)
time = float(0.10)
await asyncio.sleep(time * 60)
await user.remove_roles(gomo_role, alyanc_role)
await ctx.send(f'```Час подходит к концу по этому {user.display_name} лишаеться звания гомо часа.```')
#Альянс Command dont work
@bot.command(aliases = ['добавитьгомо'])
@commands.has_any_role('3 lvl', 800360472595267604)
async def add_pidor(ctx, member: discord.Member):
if get(member.roles, id = 801182180101324810):
await ctx.send('```Данный пользователь уже находиться в Альянсе.```')
else:
gomo_role = discord.utils.get(ctx.guild.roles, id=800360472595267604)
alyanc_role = discord.utils.get(ctx.guild.roles, id=801182180101324810)
if member == bot.user:
await ctx.send('```Нельзя сделать альянс гомо с главным гомо сервера.```')
elif member == ctx.author:
await ctx.send('```Как бы нельзя самому себе выдать, ну ты клоун.```')
else:
await ctx.send(f'```В Альянс гомо был добавлен {member.display_name}```')
await member.add_roles(alyanc_role)
if get(user.roles, id = 800360472595267604):
for i in user.roles:
if get(user.roles, id = 800360472595267604):
break
else:
await ctx.send('```Альянс был разформлен так как гомо часа сменен.```')
await member.remove_roles(alyanc_role)```
Answer the question
In order to leave comments, you need to log in
Add an event handler when changing roles, check which role has been deleted, and perform the necessary action.
@bot.event
async def on_member_update(before, after):
# Роль, которую нужно удалить со всех
role_for_removing = discord.utils.get(before.guild.roles, name='bla')
# Если роль была удалена
if len(before.roles) > len(after.roles):
for role in before.roles:
if role not in after.roles:
# удаленная роль
removed_role = role
break
# Здесь уже проверяем, была ли удалена нужная нам роль
if removed_role == role_for_removing:
for member in before.guild.members:
if role_for_removing in member.roles:
await member.remove_roles(role_for_removing)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question