RuntimeWarning: coroutine 'StageOne.__init__' was never awaited (discord.py)
Всех приветствую.
У меня есть два файла. В первом у меня описана команда для Discord-бота, а во втором классы с кнопками и сообщениями для этого бота.
Файл с командой:
@app_commands.command(name="verification-admin", description="Команды верификации для администраторов")
@app_commands.choices(action=[
app_commands.Choice(name="setup", value="setup"),
app_commands.Choice(name="set-questions", value="set-questions"),
app_commands.Choice(name="remove", value="remove")
])
async def verifadmin(self, interaction: discord.Interaction, action: app_commands.Choice[str]):
if await permchecker(interaction=interaction):
if action.value == "setup":
connection = pymysql.connect(host=db_ip, port=db_port, user=db_user, password=db_password, database=db_name)
cursor = connection.cursor()
cursor.execute("SELECT * FROM `s_verification` WHERE `server_id` = %s;", (interaction.guild.id,))
if cursor.rowcount != 0:
cursor.fetchall()
await interaction.response.send_message("У вас уже произведена установка верификации. \nЧтобы сбросить её, пропишите `/verification remove`\nЧтобы изменить настройки верификации, пропишите команду `/settings` и долистайте до страницы настроек верификации.", ephemeral=True)
return
else:
# Класс, импортирующийся из второго файла
await StageOne(interaction=interaction, bot=self.bot)
else:
await interaction.response.send_message("Ещё не готово.", ephemeral=True)
return
Класс из второго файла (StageOne):
class StageOne(discord.ui.View): # Приветствие
async def __init__(self, interaction: discord.Interaction, bot: commands.Bot):
await super().__init__()
self.bot = bot
self.data = [].append(interaction.guild_id)
embed = EmbedGen.VerifSetup.stageOne()
await interaction.response.send_message(embed=embed, view=self)
await interaction.response.defer()
@discord.ui.button(label="Далее >", style=discord.ButtonStyle.green)
async def stageone(self, interaction: discord.Interaction):
if await permchecker(interaction):
await StageTwo(interaction=interaction, data=self.data, bot=self.bot)
del self
И когда я пытаюсь использовать эту команду, мне выводится ошибка в консоли. В ответ на саму команду ничего не происходит.
/home/den/vbot/cogs/verification.py:42: RuntimeWarning: coroutine 'StageOne.__init__' was never awaited
await StageOne(interaction=interaction, bot=self.bot)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2023-04-21 15:26:18 ERROR discord.app_commands.tree Ignoring exception in command 'verification-admin'
Traceback (most recent call last):
File "/home/den/.local/lib/python3.11/site-packages/discord/app_commands/commands.py", line 841, in _do_call
return await self._callback(self.binding, interaction, **params) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/den/vbot/cogs/verification.py", line 42, in verifadmin
await StageOne(interaction=interaction, bot=self.bot)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__() should return None, not 'coroutine'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/den/.local/lib/python3.11/site-packages/discord/app_commands/tree.py", line 1248, in _call
await command._invoke_with_namespace(interaction, namespace)
File "/home/den/.local/lib/python3.11/site-packages/discord/app_commands/commands.py", line 867, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/den/.local/lib/python3.11/site-packages/discord/app_commands/commands.py", line 856, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command 'verification-admin' raised an exception: TypeError: __init__() should return None, not 'coroutine'
Как исправить эту проблему?
Источник: Stack Overflow на русском