Wolf_Yout
@Wolf_Yout

Disnake Акинатор один ответ ставит на все вопросы, в чём моя ошибка?

Код команды:
@commands.slash_command(name="akinator",description="Сыграйте в акинатора.")
    async def aki(self, ctx):
        await ctx.response.defer()
        aki = Akinator(
            child_mode=False,
            theme=Theme.from_str('characters')
        )
        first_queston = aki.start_game()
        stats = True
        component = [
            disnake.ui.Button(label="Да",style=disnake.ButtonStyle.success,custom_id="Yes"),
            disnake.ui.Button(label="Нет",style=disnake.ButtonStyle.danger,custom_id="No"),
            disnake.ui.Button(label="Я не знаю",style=disnake.ButtonStyle.success,custom_id="Idk")
        ]
        def check(msg):
            return msg.author.id == ctx.author.id
        first_queston = translator.translate(first_queston, dest="ru")
        await ctx.send(embed=disnake.Embed(title="Вопрос 1..",description=first_queston.text,color=0x228b22), components=component)
        while stats:
            try:

                btn = await bot.wait_for("button_click", check=check, timeout=90)
                #if btn.component.custom_id
                answer = Answer.from_str(btn.component.custom_id)
                aki.answer(answer)
                await btn.response.defer()
                await ctx.edit_original_response(embed=disnake.Embed(title="Очередной вопрос...",description=translator.translate(aki.question, dest="ru").text, color=0x228b22))
                win = aki.win()
                if win:
                    await ctx.edit_original_response(embed=disnake.Embed(title=f"Это {translator.translate(win.name, dest='ru').text}!",description=translator.translate(win.description, dest="ru").text,color=0x228b22).set_image(url = win.absolute_picture_path))
                    stats = False
                else:
                    return
            except asyncio.TimeoutError:
                await ctx.send(embed=disnake.Embed(title="Игра закончена!",description="Слишком долго не было взаимодействия с кнопками!"))
                stats = False

И с таким кодом бот выдаёт ответ сразу, и судя по всему, потому что расставил на все вопросы один ответ:
image.png
  • Вопрос задан
  • 79 просмотров
Решения вопроса 1
Wolf_Yout
@Wolf_Yout Автор вопроса
Спустя долгое время, до меня дошло:
@commands.slash_command(name="akinator",description="Сыграйте в акинатора.")
    async def aki(self, ctx):
        await ctx.response.defer()
        aki = Akinator(
            child_mode=False,
            theme=Theme.from_str('characters')
        )
        first_queston = aki.start_game()
        stats = True
        component = [
            disnake.ui.Button(label="Да",style=disnake.ButtonStyle.success,custom_id="Yes"),
            disnake.ui.Button(label="Нет",style=disnake.ButtonStyle.danger,custom_id="No"),
            disnake.ui.Button(label="Я не знаю",style=disnake.ButtonStyle.success,custom_id="Idk")
        ]
        def check(msg):
            return msg.author.id == ctx.author.id
        first_queston = translator.translate(first_queston, dest="ru")
        await ctx.send(embed=disnake.Embed(title="Вопрос 1..",description=first_queston.text,color=0x228b22), components=component)
        while aki.progression <= 80 and stats:
            try:

                btn = await bot.wait_for("button_click", check=check, timeout=90)
                #if btn.component.custom_id
                answer = Answer.from_str(btn.component.custom_id)
                aki.answer(answer)
                await btn.response.defer()
                await ctx.edit_original_response(embed=disnake.Embed(title="Очередной вопрос...",description=translator.translate(aki.question, dest="ru").text, color=0x228b22), components=component)
                
            except asyncio.TimeoutError:
                await ctx.send(embed=disnake.Embed(title="Игра закончена!",description="Слишком долго не было взаимодействия с кнопками!"))
                stats = False
        win = aki.win()
        if win:
            await ctx.edit_original_response(embed=disnake.Embed(title=f"Это {translator.translate(win.name, dest='ru').text}!",description=translator.translate(win.description, dest="ru").text,color=0x228b22).set_image(url = win.absolute_picture_path), components=None)
            stats = False
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы