我正试图让机器人从1到x进行抽奖命令,然后选择y个中奖号码
@bot.command(name='raffle',
description="Command usage: !raffle x y",
brief="Picks a number between 0 and the input x y times",
pass_context=True)
async def raffle(ctx, x, y):
message = await bot.say(str('Generating random numbers...'))
await sleep(1)
await bot.edit_message(message, new_content="Assessing the tallies...", embed=None)
await sleep(1)
await bot.edit_message(message, new_content="Numbercrunching...", embed=None)
await sleep(1)
await bot.edit_message(message, new_content="The number is.. *drum roll*", embed=None)
await sleep(1)
pool = list(range(1, (x)))
z = random.sample(pool, k=(y))
await bot.say(z)
答案 0 :(得分:0)
discord将参数保存为字符串的方式
@bot.command(pass_context=True)
async def example(ctx,x):
print(type(x))
将打印
<class 'str'>
并且由于所有range
参数和k
的{{1}}参数都采用整数,因此必须分别将random.sample
和x
转换为int
话虽如此,改变
y
到
pool = list(range(1, (x)))
z = random.sample(pool, k=(y))
await bot.say(z)
以及每个pool = list(range(1, int(x)))
z = random.sample(pool, k=int(y))
await bot.say(z)
至await sleep(1)
应该可以解决问题