提出问题并设置和回答discord.py

时间:2020-10-02 17:05:27

标签: discord.py

因此,每当有人执行命令s!work时,我都在尝试随机回答一个问题,唯一的问题是我对此尝试了多次,或者发送了所有列表,或者出现错误!这是我的代码:

@client.command()
async def work(ctx):
    await open_account(ctx.author)
    users = await get_bank_data()
    user = ctx.author
    def check(m):
        return m.author.id == ctx.author.id
    question = [
        (await ctx.send(file=discord.File('work1.png')), 'DARLING in the FRANXX'),
        (await ctx.send(file=discord.File('work2.png')), 'Trinity Seven')
    ]
    questions = shuffle(question)
    await ctx.send("What is the title name of this anime?")
    await asyncio.sleep(1)
    await ctx.send(questions)
    msg = await client.wait_for('message', check=check)
    if msg.content == answer:
        earnings = random.randrange(300, 500)
        await ctx.send(f"You did good! You got an earning of **{earnings}** coins!")
    else:
        earnings = random.randrange(0, 200)
        await ctx.send(f"Did you even try? You got **{earnings}** coins!")

    users[str(user.id)]["wallet"] += earnings

    with open("mainbank.json", "w") as f:
        users = json.dump(users, f)

1 个答案:

答案 0 :(得分:0)

在您的question列表中,您send甚至在对列表进行任何操作之前都会先问两个问题,这是故意的吗?

random.shuffle只是重新排列了question列表中的项目,因此您只是发送整个列表。您可能正在寻找random.choice