Discord.py if语句中的值不更新,不协调python

Discord.py if语句中的值不更新,不协调python,discord.py,Discord.py,只有一个选项时,代码正常工作: 如果食物=‘苹果’: 然而,当我加上“苹果”或“稻草”- 每当选择“肉”或“面食”时,份量就用“苹果”或“稻草”代替“肉”或“面食”的份量 我不知道该怎么做。我想要多种选择的食物以及它们的份量 options = ('straw', 'meat', 'apple', 'pasta') status = ('Skinny', 'Average', 'Plump') food = random.choice(option

只有一个选项时,代码正常工作: 如果食物=‘苹果’:

然而,当我加上“苹果”或“稻草”- 每当选择“肉”或“面食”时,份量就用“苹果”或“稻草”代替“肉”或“面食”的份量

我不知道该怎么做。我想要多种选择的食物以及它们的份量

        options = ('straw', 'meat', 'apple', 'pasta')
        status = ('Skinny', 'Average', 'Plump')
        food = random.choice(options)
        statusr = random.choice(status)

           if food == 'apple' or 'straw':
                if statusr == "Skinny":
                    servingr = 'This can feed 0 people'
                    embed = discord.Embed(title="", description="You get a **{} {}!**\n*Serving: {}*".format(statusr, food, servingr), color=0xE69138)
                    embed.set_footer(text="Press {} to add this to the pile! Otherwise, press {}".format(check, fail))
                    sendy = await ctx.send(embed=embed)
                    await sendy.add_reaction(check)
                    await sendy.add_reaction(fail)  
                elif statusr == "Average":
                    servingr = 'This can feed 0 people'
                    embed = discord.Embed(title="", description="You get a **{} {}!**\n*Serving: {}*".format(statusr, food, servingr), color=0xE69138)
                    embed.set_footer(text="Press {} to add this to the pile! Otherwise, press {}".format(check, fail))
                    sendy = await ctx.send(embed=embed)
                    await sendy.add_reaction(check)
                    await sendy.add_reaction(fail)  
                elif statusr == "Plump":
                    servingr = 'This can feed 0 people'
                    embed = discord.Embed(title="", description="You get a **{} {}!**\n*Serving: {}*".format(statusr, food, servingr), color=0xE69138)
                    embed.set_footer(text="Press {} to add this to the pile! Otherwise, press {}".format(check, fail))
                    sendy = await ctx.send(embed=embed)
                    await sendy.add_reaction(check)
                    await sendy.add_reaction(fail)  
            elif food == 'meat' or 'pasta':
                if statusr == "Skinny":
                    servingr = 'This can feed 1 people'
                    embed = discord.Embed(title="", description="You get a **{} {}!**\n*Serving: {}*".format(statusr, food, servingr), color=0xE69138)
                    embed.set_footer(text="Press {} to add this to the pile! Otherwise, press {}".format(check, fail))
                    sendy = await ctx.send(embed=embed)
                    await sendy.add_reaction(check)
                    await sendy.add_reaction(fail)  
                elif statusr == "Average":   
                    servingr = 'This can feed 2 people'
                    embed = discord.Embed(title="", description="You get a **{} {}!**\n*Serving: {}*".format(statusr, food, servingr), color=0xE69138)
                    embed.set_footer(text="Press {} to add this to the pile! Otherwise, press {}".format(check, fail))
                    sendy = await ctx.send(embed=embed)
                    await sendy.add_reaction(check)
                    await sendy.add_reaction(fail)  
                elif statusr == "Plump":
                    servingr = 'This can feed 4 people'               
                    embed = discord.Embed(title="", description="You get a **{} {}!**\n*Serving: {}*".format(statusr, food, servingr), color=0xE69138)
                    embed.set_footer(text="Press {} to add this to the pile! Otherwise, press {}".format(check, fail))
                    sendy = await ctx.send(embed=embed)
                    await sendy.add_reaction(check)
                    await sendy.add_reaction(fail)                
            reaction, author = await self.bot.wait_for("reaction_add", timeout=60, check=reactioncheck)
            if reaction.emoji == (check):
                with open("list.json", "r") as f:
                    data = json.load(f)
                try:
                    today = date.today()
                    item2 = ("{} {} {} {}/{}".format(statusr, food, servingr, today.month, today.day))
                    data[itemlist].append(item2)
                except KeyError:
                    data[itemlist] = [item2]
                with open("list.json", "w") as f:
                    json.dump(data, f)
                    await ctx.send("Succesfully added '{}' to the list '{}'".format(food, itemlist))
            if reaction.emoji == (fail):
                await ctx.send("Not added.")

您的尺码可以是以下任一种:(“小”、“瘦”、“一般”), 但是你要检查“小”、“中”和“大”,所以有这个错误。此外,您描述问题的方式:

第一种食物是苹果,它的效果很好。如果它很小,它会加上“这可以养活4个人!”

这也是不对的,对吧?请再次检查,也许可以编辑您的问题

编辑:


这也总是会失败,对吗?因为servingr不在这里的范围之内,所以只能从if语句内部访问它

我不理解这个问题;您预期会发生什么?您在肉类代码区域中使用了
servinglist
,但没有在任何地方定义它,它是什么?另外,您的
状态r
的可能选项是
(“小”、“瘦”、“平均”)
,但是您可以在
if
块中检查
“小”
“中”
“大”
。抱歉,我编辑了代码。这是试图解决问题时的上一次迭代。问题是,我希望不同的食物有不同的份量,并将它们添加到列表中。例如,apple:small(供1人食用)medium(供1人食用)和meat:small(供5人食用)medium(供5人食用)但是,当调用embed并选择meat时,它使用apple的服务大小。抱歉,我编辑了代码。这是试图解决问题时的上一次迭代。问题是,我希望不同的食物有不同的份量,并将它们添加到列表中。例如,apple:small(供1人食用)medium(供1人食用)和meat:small(供5人食用)medium(供5人食用)然而,当调用embed并选择meat时,它使用的是apple的服务大小。我不知道,您的描述再次毫无意义,代码中根本没有发生任何事情。然而,我看到了我认为的其他错误。您的变量servingr不能在if范围之外访问。可能会在fail=…”下创建变量,所以servingr=“”对不起,我实际上再次更新了它,使其更加清晰。我找到了原因。问题是,当我使用or语句时,服务大小使用第一个语句。如果食物=‘苹果’或‘稻草’服务=‘[供2人食用!】如果食物=‘肉’或‘面食’服务=‘[供3人食用!】当选择肉或面食时,它使用苹果和稻草的服务价值。
try:
    today = date.today()
    item2 = ("{} {} {} {}/{}".format(statusr, food, servingr, today.month, today.day))
    data[itemlist].append(item2)