我正在制作一个typerace机器人(discord.py)

2024-10-02 00:24:11 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:-

client = commands.Bot(command_prefix='>', help_command = None)

tr_questions_file = open("typerace_questions.txt", 'r')
tr_total_q = 10 # total number or questions
tr_questions = []

@client.command(aliases = ['tr', 'typeRace'])
async def typerace(ctx):
    starttime = time.time()
    num = random.randint(0, tr_total_q)
    question = tr_questions[num-1]
    print(question)
    timer = 30.0
    embed = discord.Embed(title = "TYPE RACE", description = f"{question}")
    await ctx.reply(embed = embed)

    def is_correct(msg):
        return msg.author==ctx.author

    try:
        guess = await client.wait_for('message', check=is_correct, timeout=timer)
        print(guess.content)
    except asyncio.TimeoutError:
        return await ctx.reply("You took too long to type :(")

    if guess.content == question:
        fintime = time.time()
        total = fintime - starttime
        await ctx.send(f"You got it!!\nYou got it in {round(total)} seconds")

    else:
        await ctx.send(f"Nope, that is not correct!!\nTry again using ``>tr``")

client.run(token)

不和谐:- look at this picture

在终端:- look at this picture

问题和答案都是匹配的,但它仍然在说错话。我不知道发生了什么事


Tags: clienttimeisdefembedawaittrcommand

热门问题