简体   繁体   English

如何在 discord.py 中制作 kinator 命令?

[英]How to make akinator command in discord.py?

I am making my bot, I wanted to add a command on which when I call it as.tell it will send me questions and enter n or y .我正在制作我的机器人,我想添加一个命令,当我将其称为 as.tell 时,它会向我发送问题并输入ny But I am stuck in the code, the following code is not running.WHat's the problem with this anyone pls help.This is the code:但是我被困在代码中,以下代码没有运行。这是什么问题,任何人请帮忙。这是代码:

import akinator
@client.command()
async def tell(ctx):
    def check(msg):
        return msg.author == ctx.author and msg.channel == ctx.channel and msg.content.lower() in ["y", "n"]
    msg = await client.wait_for("message", check=check)
    try:
        aki = akinator.Akinator()
        q = aki.start_game()
        while await ctx.send(aki.progression <= 80):
            if msg.content.lower() == "b":
                try:
                    await ctx.send(aki.back())
                except akinator.CantGoBackAnyFurther:
                    pass
            else:
                await ctx.send(aki.answer(msg))
        aki.win()
        correct = await ctx.send(await client.wait_for(f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?\n{aki.first_guess['absolute_picture_path']}\n\t", check=check))
        if correct.lower() == "yes" or correct.lower() == "y":
            await ctx.send("Yay\n")
        else:
            await ctx.send("Oof\n")
    except Exception as e:
        await ctx.send(e)
@bot.command(aliases=["aki"])
async def akinator(ctx):
    await ctx.send("Akinator is here to guess!")
    def check(msg):
        return msg.author == ctx.author and msg.channel == ctx.channel and msg.content.lower() in ["y", "n","p","b"]
    try:
        aki = ak.Akinator()
        q = aki.start_game()
        while aki.progression <= 80:
            await ctx.send(q)
            await ctx.send("Your answer:(y/n/p/b)")
            msg = await bot.wait_for("message", check=check)
            if msg.content.lower() == "b":
                try:
                    q=aki.back()
                except ak.CantGoBackAnyFurther:
                    await ctx.send(e)
                    continue
            else:
                try:
                    q = aki.answer(msg.content.lower())
                except ak.InvalidAnswerError as e:
                    await ctx.send(e)
                    continue
        aki.win()
        await ctx.send(f"It's {aki.first_guess['name']} ({aki.first_guess['description']})! Was I correct?(y/n)\n{aki.first_guess['absolute_picture_path']}\n\t")
        correct = await bot.wait_for("message", check=check)
        if correct.content.lower() == "y":
            await ctx.send("Yay\n")
        else:
            await ctx.send("Oof\n")
    except Exception as e:
        await ctx.send(e)```

For importing Akinator(), it's not akinator but akinator.async_aki .对于导入 Akinator(),它不是akinator而是akinator.async_aki

from akinator.async_aki import Akinator

Or, in your code, replace aki = akinator.Akinator() with aki = akinator.async_aki.Akinator()或者,在您的代码中,将aki = akinator.Akinator()替换为aki = akinator.async_aki.Akinator()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM