Приветствую. Проблема с кодом, роль мута не снимается спустя время. Как исправить?
@bot.command()
@commands.has_permissions(view_audit_log = True)
@commands.cooldown(1, 3, commands.BucketType.guild)
async def mute(ctx, member: discord.Member = None, duration = None, *, reason = None):
mute_role = discord.utils.get(ctx.guild.roles, name = "Muted")
if not mute_role:
mute_role = await ctx.guild.create_role(name = "Muted")
for channel in ctx.guild.channels:
await channel.set_permissions(mute_role, send_messages=False, connect=False)
await member.add_roles(mute_role)
if duration:
duration = duration.lower()
time_parts = {"y": 31536000, "mon": 2592000, "w": 604800, "d": 86400, "h": 3600, "min": 60, "s": 1}
duration_seconds = sum(int(num) * time_parts[unit] for num, unit in zip(duration.split()[:-1:2], duration.split()[1::2]))
unmute_time = datetime.datetime.utcnow() + timedelta(seconds=duration_seconds)
await member.add_roles(mute_role)
emb0 = discord.Embed(
title = f'<:muted:1126853362999111740> Participant has been successfully muted.',
description = f'<:warn:1121741505548267520> The participant has been assigned the mute role, and their ability to send messages has been blocked.',
color = 0x0089FF
)
emb0.add_field(
name = f'<:moderator:1121741479216427088> Moderator:',
value = f'{ctx.author.mention}',
inline = True
)
emb0.add_field(
name = f'<:user:1121742132089212998> Muted:',
value = f'{member.mention}',
inline = True
)
emb0.add_field(
name = f'<:info:1121741519540453386> Reason:',
value = f'{reason}',
inline = False
)
emb0.add_field(
name = f'<:timeout:1121741499986616330> Duration:',
value = f'{duration}',
inline = False
)
emb0.set_author(
name = f'Turo Team',
icon_url = 'https://media.discordapp.net/attachments/1056666785484636230/1121768764267048980/Frame_5.png?width=384&height=384'
)
await ctx.send(embed=emb0)
await unmute(member, mute_role, unmute_time)
else:
await member.add_roles(mute_role, reason=reason)
emb1 = discord.Embed(
title = f'<:muted:1126853362999111740> Participant has been successfully muted.',
description = f'<:warn:1121741505548267520> The participant has been assigned the mute role, and their ability to send messages has been blocked.',
color = 0x0089FF
)
emb1.add_field(
name = f'<:moderator:1121741479216427088> Moderator:',
value = f'{ctx.author.mention}',
inline = True
)
emb1.add_field(
name = f'<:user:1121742132089212998> Muted:',
value = f'{member.mention}',
inline = True
)
emb1.add_field(
name = f'<:info:1121741519540453386> Reason:',
value = f'{reason}',
inline = False
)
emb1.add_field(
name = f'<:timeout:1121741499986616330> Duration:',
value = f'The time is not specified',
inline = False
)
emb1.set_author(
name = f'Turo Team',
icon_url = 'https://media.discordapp.net/attachments/1056666785484636230/1121768764267048980/Frame_5.png?width=384&height=384'
)
await ctx.send(embed=emb1)
async def unmute(member, mute_role, unmute_time):
while datetime.datetime.utcnow() < unmute_time:
await asyncio.sleep((unmute_time - datetime.datetime.utcnow()).total_seconds())
if mute_role in member.roles:
await member.remove_roles(mute_role)