@bot.command()
async def mute(ctx, member: discord.Member, duration: str, *, reason: str):
try:
await ctx.message.delete()
duration_mute = int(duration[:1]) # duration = 1h. [0:] = 1
duration_time = str(duration[1:]) # duration = 1h. [:0] = h
duration_timer = None # timedelta
if any(map(duration_time.lower().startswith, ['s', 'с'])):
duration_timer = datetime.datetime.utcnow() + datetime.timedelta(hours=3, seconds=int(duration_mute))
if any(map(duration_time.lower().startswith, ['m', 'м'])):
duration_timer = datetime.datetime.utcnow() + datetime.timedelta(hours=3, minutes=int(duration_mute))
if any(map(duration_time.lower().startswith, ['h', 'ч'])):
duration_timer = datetime.datetime.utcnow() + datetime.timedelta(hours=int(duration_mute)+3)
if any(map(duration_time.lower().startswith, ['d', 'д'])):
duration_timer = datetime.datetime.utcnow() + datetime.timedelta(hours=3, days=int(duration_mute))
a = await member.timeout(duration_timer.astimezone(pytz.timezone("Europe/Moscow")), reason=reason)
embed = discord.Embed(
title="Пользователь замучен",
color=discord.Color.red(),
description=f"Наказан: {member.mention}\nЗамучен: {ctx.author.mention}\nСрок: {duration} мин\nОкончание: {end_time_str}\nПричина: {reason}"
)
await ctx.send(embed=embed)
except discord.Forbidden:
embed = discord.Embed(
title="Ошибка",
color=discord.Color.red(),
description="У меня недостаточно прав для выполнения этой команды."
)
await ctx.send(embed=embed)
except commands.MissingRequiredArgument:
embed = discord.Embed(
title="Ошибка",
color=discord.Color.red(),
description="Некоторые обязательные аргументы отсутствуют. Используйте команду в следующем формате: !mute @пользователь срок_мута(в минутах) причина."
)
await ctx.send(embed=embed)
except commands.BadArgument:
embed = discord.Embed(
title="Ошибка",
color=discord.Color.red(),
description="Неверный формат аргумента. Пожалуйста, проверьте правильность введенных данных."
)
await ctx.send(embed=embed)
Нельзя указывать таймаут больше 28 дней.
Код нужно немного доработать.