Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
451 views
in Technique[技术] by (71.8m points)

python - 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. 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?
{aki.first_guess['absolute_picture_path']}
", check=check))
        if correct.lower() == "yes" or correct.lower() == "y":
            await ctx.send("Yay
")
        else:
            await ctx.send("Oof
")
    except Exception as e:
        await ctx.send(e)
question from:https://stackoverflow.com/questions/65904594/how-to-make-akinator-command-in-discord-py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
@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)
{aki.first_guess['absolute_picture_path']}
")
        correct = await bot.wait_for("message", check=check)
        if correct.content.lower() == "y":
            await ctx.send("Yay
")
        else:
            await ctx.send("Oof
")
    except Exception as e:
        await ctx.send(e)```

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...