【发布时间】:2021-11-13 07:56:12
【问题描述】:
我正在制作一个不和谐的机器人,我已经制作了一个掷骰子系统,但我想改进它。我想一次掷多个骰子,就像 Avrae 一样。
@client.command(aliases=['r', 'dado', 'dice'])
async def roll(ctx, dados='', numero=20, conta='', ficha=''):
rolagem = random.randint(1,int(numero))
if conta == '':
total = (int(rolagem))
elif conta == '+':
total = (int(rolagem) + int(ficha))
elif conta == '-':
total = (int(rolagem) - int(ficha))
elif conta == 'x':
total = (int(rolagem) * int(ficha))
elif conta == '/':
total = (int(rolagem) / int(ficha))
if ficha == '':
ficha = ''
if total < 0:
total = '1'
if total == 0:
total == '1'
if rolagem == 20:
rolagem = '**20**'
if rolagem == 1:
rolagem = '**1**'
await ctx.send(f'{ctx.author.mention} ???? \n**Resultado**: D{numero} ({rolagem}) {conta} {ficha}\n**Total**: {total}')
因此,该命令应该像:(前缀)r(要掷骰子的数量)(骰子),并显示如下结果:(掷骰子的数量):(骰子结果)(骰子结果的总和) 例如:-r 5 d20; 5 D20 的结果:(1、5、8、16、20)(总和)。 我想知道我应该怎么做
【问题讨论】:
-
这很简单。您有 1 个案例,现在您需要解决
n案例。考虑使用循环包装您的代码(例如,运行n次的 for 循环),将结果添加到结果列表中,然后返回该列表的总和。
标签: python discord discord.py