我正在制作我的机器人,我想添加一个命令,当我将其称为 .tell 时,它会向我发送问题并输入 n
或 y
。但是我被代码卡住了,下面的代码没有运行。有什么问题请大家帮忙。这是代码:
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)
答案 0 :(得分:0)
@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)```