Python 3.x 无法添加变量
因此,我尝试制作一个python discord机器人,其中包含PVP功能(基于Jojo的奇异冒险)。我一直有这样一个逻辑错误,奖金/其他奖金没有添加到机会中。对不起,如果这不合理,但我一直在努力找出它的一段时间。 以下是我认为此错误来自的代码:Python 3.x 无法添加变量,python-3.x,discord.py,Python 3.x,Discord.py,因此,我尝试制作一个python discord机器人,其中包含PVP功能(基于Jojo的奇异冒险)。我一直有这样一个逻辑错误,奖金/其他奖金没有添加到机会中。对不起,如果这不合理,但我一直在努力找出它的一段时间。 以下是我认为此错误来自的代码: elif otherstando == "Ultimate Life Form Vampiric Hamonic Spin Ratt Platinum Requiem Over Heaven Under Hell Alternate
elif otherstando == "Ultimate Life Form Vampiric Hamonic Spin Ratt Platinum Requiem Over Heaven Under Hell Alternate Universe Act 4 Love Train Bites The Dust":
otherbonus = 100000000000000000000000000000000000000000000000
otherbonus = otherbonus + other
bonus = bonus + me
print(bonus)
embed = discord.Embed(title='***Your Bizarre Adventure***', description="A mini JJBA feature [<@"+ str(ctx.message.author.id) + "> / <@" + str(member.id) + ">]", color=0xFF000)
embed.add_field(name="Online PVP", value="<@" + str(ctx.message.author.id) + "> [" + stando + "] __**VS**__ <@" + str(member.id) + "> [" + otherstando + "]", inline=False)
await ctx.send(embed=embed)
otheron = "True"
meon = "True"
print("me " + str(ctx.message.author.id) + " " + str(me))
print("other " + str(member.id) + " " + str(other))
elif otherstando==“终极生命形式吸血鬼哈莫尼克旋转拉特白金安魂曲穿越天堂地狱交替宇宙第4幕爱情列车咬尘埃”:
其他奖金=10000000000000000000000000000000000000000000000000000
其他奖金=其他奖金+其他
奖金=奖金+我
印刷品(奖金)
embed=discord.embed(title='***你的奇异冒险***',description=“迷你JJBA功能[/]”,color=0xFF000)
嵌入.add_字段(name=“Online PVP”,value=“[”+stando+“]”]\u**VS**\u[“+otherstando+”]”,inline=False)
等待ctx.send(嵌入=嵌入)
otheron=“True”
meon=“真的”
打印(“me”+str(ctx.message.author.id)+“+str(me))
打印(“其他”+str(member.id)+“+str(其他))
打印(奖金)打印出代码中没有的180。我可以发送整个代码,如果它有帮助,只要告诉我的答复。这个命令工作得很好,但是奖金没有增加。无论如何,请提前感谢。可能是
奖金
是180,因为您将奖金定义为奖金=奖金+me
。例如,如果me
为100,而stando
为Killer Queen[Alternative Universe]
。你可以得到号码。在你的代码中,你有一些事情要做。第一件事是你有一个生成数字的随机函数。这两行代码
other = random.randint(1, 1000)
me = random.randint(1, 1000)
它们可以为other
和me
生成1到1000之间的值
让我们假设me
的值为160
我们还假设stando
的值为Anubis
,那么if语句为true,并且bonus
被分配20
因此,bonus
的值是20
,me
的值是160
下面的代码是
bonus = bonus + me # resulting in 20 + 160 = 180
因此,您的代码可以获得180的值
此外,我还想为您提供一些额外的输入,以改进您的代码
您可以将if语句中的所有值放入如下列表中
check_list = ["The Emperor","Anubis", "Ratt", "Osiris", "White Album", "Mr. President", "The Sun"]
check_list = ["The Emperor","Anubis", "Ratt", "Osiris", "White Album", "Mr. President", "The Sun"]
if (stando or otherstando) in check_list:
bonus = otherbonus = 20
然后你可以查一下
if stando in check_list:
这将与
if stando == "The Emperor" or otherstando == "Anubis" or otherstando == "Ratt" or otherstando == "Osiris" or otherstando == "White Album" or otherstando == "Mr. President" or otherstando == "The Sun":
bonus = 20
我还想给你们提供更多的选择。
试试这个例子,看看你是否可以使用类似的东西
x = 10
y = 20
z = [10,11,12,13,14,15]
if (x or y) in z:
print('either x or y has a value from z')
else:
print('neither x nor y has a value from z')
如果对stando
和otherstando
进行了相同的检查,并且如果您要将相同的值分配给bonus
和otherbonus
,您可以执行与上述示例类似的操作
也许你可以试试这样的
check_list = ["The Emperor","Anubis", "Ratt", "Osiris", "White Album", "Mr. President", "The Sun"]
check_list = ["The Emperor","Anubis", "Ratt", "Osiris", "White Album", "Mr. President", "The Sun"]
if (stando or otherstando) in check_list:
bonus = otherbonus = 20
请张贴一个最小的可复制的例子。我们不会阅读你的100行无关代码。为你推荐。如果stando==“皇帝”或stando==“阿努比斯”或stando==“拉特”或stando==“奥西里斯”或stando==“白相册”或stando==“总统先生”或stando==“太阳”,则无需使用此代码:如果stando in(“皇帝”、“阿努比斯”、“拉特”、“奥西里斯”、“白相册”、“总统先生”),您也可以将代码编写为
,“太阳报”):
我该如何解决这个问题?