Выдаёт ошибку TypeError: '<=' not supported between instances of 'str' and 'int' При использовании функции asyncio.sleep в slash командах
При использовании slash(/) команды на мут ботом в дискорде выдаёт ошибку:
Traceback (most recent call last):
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_client.py", line 1202, in _on_socket_response
await self._process_interaction(payload["d"])
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_client.py", line 1360, in _process_interaction
await self._on_slash_command(inter)
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_client.py", line 1260, in _on_slash_command
raise err
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_client.py", line 1255, in _on_slash_command
await app_command.invoke(inter)
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_core.py", line 216, in invoke
raise err
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_core.py", line 212, in invoke
await self._maybe_cog_call(self._cog, interaction, interaction.data)
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\slash_core.py", line 37, in _maybe_cog_call
return await self(inter, **params)
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\site-packages\dislash\application_commands\core.py", line 72, in __call__
return await self.func(*args, **kwargs)
File "C:\Users\Fenix\Desktop\bots\InfinityBot\bot.py", line 844, in mute
await asyncio.sleep(time * 5)
File "C:\Users\Fenix\AppData\Local\Programs\Python\Python39\lib\asyncio\tasks.py", line 638, in sleep
if delay <= 0:
TypeError: '<=' not supported between instances of 'str' and 'int'
Сам код:
@slash.command(
guild_ids=test_guilds,
name="mute",
description="mute in all channel",
options=[
Option("user", "Intruder", Type.USER),
Option("time", "Mut Time", Type.STRING),
Option("reason", "Clause of the Rules", Type.STRING),
]
)
@slash_commands.has_role(862061269300936759)
async def mute(inter, user, time, reason):
mute_role = discord.utils.get(inter.guild.roles, id=876733754591293450)
emb = discord.Embed(color=discord.Color.blurple())
emb.title = str(user)
emb.description = (
f"**Модератор:** `{inter.author}`\n"
f"**Нарушитель:** `{user}`\n"
f"**Время:** `{time}`\n"
f"**Причина:** `{reason}`\n"
)
emb.set_thumbnail(url=inter.author.avatar_url)
await inter.send(embed = emb)
await user.add_roles(mute_role)
await asyncio.sleep(time * 5)
await user.remove_roles(mute_role)
Роль Мута Даётся, но не забирается. Прошу помочь в решении данной проблемы.
Ответы (1 шт):
Автор решения: RAINGM
→ Ссылка
Как вы запускаете функцию, можно пример?
Задайте тип параметра time заранее
@slash.command(
guild_ids=test_guilds,
name="mute",
description="mute in all channel",
options=[
Option("user", "Intruder", Type.USER),
Option("time", "Mut Time", Type.STRING),
Option("reason", "Clause of the Rules", Type.STRING),
]
)
@slash_commands.has_role(862061269300936759)
async def mute(inter, user, time: int, reason):
mute_role = discord.utils.get(inter.guild.roles, id=876733754591293450)
emb = discord.Embed(color=discord.Color.blurple())
emb.title = str(user)
emb.description = (
f"**Модератор:** `{inter.author}`\n"
f"**Нарушитель:** `{user}`\n"
f"**Время:** `{time}`\n"
f"**Причина:** `{reason}`\n"
)
emb.set_thumbnail(url=inter.author.avatar_url)
await inter.send(embed = emb)
await user.add_roles(mute_role)
await asyncio.sleep(time * 5)
await user.remove_roles(mute_role)