Python 向随机命令添加权重时使用括号
我试图给我的随机代码添加权重。我设法增加了权重,但回答中有括号。有人能帮我吗?谢谢Python 向随机命令添加权重时使用括号,python,discord.py,discord.py-rewrite,Python,Discord.py,Discord.py Rewrite,我试图给我的随机代码添加权重。我设法增加了权重,但回答中有括号。有人能帮我吗?谢谢 @bot.command() async def sus(ctx): dre = ["Cyan faked trash!", "Red was following me!", "White vented right in front of me!", "Pink i
@bot.command()
async def sus(ctx):
dre = ["Cyan faked trash!",
"Red was following me!",
"White vented right in front of me!",
"Pink is so sus",
"Brown sabotaged the reactor!",
"**ELECTRICAL**",
"Purple is the- oh, he's dead.",
]
await ctx.send(f'{random.choices(dre, weights=(500, 500, 500, 500, 500, 100, 500))}')
random.choices
始终返回一个列表。由于该列表将始终包含单个项目,因此每次只需使用第一个元素:
choice = random.choices(dre, weights=(500, 500, 500, 500, 500, 100, 500))[0]
await ctx.send(choice)
输出是什么?你的意思是什么?当你运行命令时会发生什么,机器人会发送什么消息?哦,它会发送:[“Pink is so sus”]你是否尝试过
random.choice
而不是random.choices
?