我是 discord.py 的新手,我正在尝试制作一个 gacha 机器人,其中包含 SR、SSR 和 UR 卷,我想将它们分成不同的显示机会,当有人输入命令时。 SR或3星为94.3%,SSR或4星为5.1%,UR或5星为0.6%。
这是代码。
@client.command()
@commands.cooldown(1, 4, commands.BucketType.user)
async def wish(ctx):
items = [
discord.Embed(title = "Wish Successfull", description = "You get 3 :star: Ebony Bow <:EbonyBow:857220938571317248> (Bow Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 3 :star: Raven Bow <:RavenBow:857221178338574357> (Bow Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 3 :star: Recurve Bow <:RecurveBow:857221810932547594> (Bow Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 4 :star: Alley Hunter <:AlleyHunter:857262273805287434> (Bow Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 4 :star: Blackcliff Warbow <:BlackcliffWarbow:857262272656441345> (Bow Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 4 :star: Compound Bow <:CompoundBow:857262272622493736> (Bow Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 5 :star: Lost Prayer to the Sacred Winds <:LostPrayertotheSacredWinds:857281184492552213> (Catalyst Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 5 :star: Memory of Dust <:MemoryofDust:857281131413635122> (Catalyst Weapon).", color = ctx.author.color),
discord.Embed(title = "Wish Successfull", description = "You get 5 :star: Skyward Atlas <:SkywardAtlas:857281156763746364> (Catalyst Weapon).", color = ctx.author.color)]
randomitem = random.choice(items)
await ctx.send(embed=randomitem)
答案 0 :(得分:0)
他们都有相同的机会被发送。
您可以在列表中添加更多相同的项目以使其更常见。但更好的方法是在数据库中为它们分配一个百分比,然后根据这些机会创建一个函数来发送一个。
答案 1 :(得分:0)
正如上一个答案所说,它说 all have the same chance of being sent.
因为我查看了代码,所以我决定让它更简洁以使其更具可读性 :D。
代码:
@client.command()
@commands.cooldown(1, 4, commands.BucketType.user)
async def wish(ctx):
items = [
"3 :star: Ebony Bow <:EbonyBow:857220938571317248> (Bow Weapon)",
"3 :star: Raven Bow <:RavenBow:857221178338574357> (Bow Weapon).",
"3 :star: Recurve Bow <:RecurveBow:857221810932547594> (Bow Weapon)",
"4 :star: Alley Hunter <:AlleyHunter:857262273805287434> (Bow Weapon).",
"4 :star: Blackcliff Warbow <:BlackcliffWarbow:857262272656441345> (Bow Weapon).",
"4 :star: Compound Bow <:CompoundBow:857262272622493736> (Bow Weapon).",
"5 :star: Lost Prayer to the Sacred Winds <:LostPrayertotheSacredWinds:857281184492552213> (Catalyst Weapon).",
"5 :star: Memory of Dust <:MemoryofDust:857281131413635122> (Catalyst Weapon).",
"5 :star: Skyward Atlas <:SkywardAtlas:857281156763746364> (Catalyst Weapon)."
]
randomitem = discord.Embed(title = "Wish Successfull", description = f"You get {random.choice(items)}", color = ctx.author.color)]
await ctx.send(embed=randomitem)