大家好,我正在用 Python 编写一个 Discord 机器人,我想编写一个掷骰子命令。我认为我做错了什么。这是代码:
@client.command()
async def rolldice(ctx):
dice4 = ["1","2","3","4"]
dice6 = ["1","2","3","4","5","6"]
dice8 = ["1","2","3","4","5","6","7","8"]
dice10 = ["1","2","3","4","5","6","7","8","9","10"]
dice12 = ["1","2","3","4","5","6","7","8","9","10","11","12"]
dice20 = ["1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20"]
message = await ctx.send("Choose a number:\n**4**, **6**, **8**, **10**, **12**, **20** ")
def check4(m):
return m.author == ctx.author and m.content == "4"
try:
await client.wait_for('message', check=check4, timeout=30.0)
coming = await ctx.send("Here it comes...")
time.sleep(1)
await coming.delete()
await ctx.send(f"**{random.choice(dice4)}**")
except asyncio.TimeoutError:
await message.delete()
await ctx.send("Procces has been canceled because you didn't answer in **30** second!")
def check6(m):
return m.author == ctx.author and m.content == "6"
try:
await client.wait_for('message', check=check6, timeout=30.0)
coming = await ctx.send("Here it comes...")
time.sleep(1)
await coming.delete()
await ctx.send(f"**{random.choice(dice6)}**")
except asyncio.TimeoutError:
await message.delete()
await ctx.send("Procces has been canceled because you didn't answer in **30** second!")
def check8(m):
return m.author == ctx.author and m.content == "8"
try:
await client.wait_for('message', check=check8, timeout=30.0)
coming = await ctx.send("Here it comes...")
time.sleep(1)
await coming.delete()
await ctx.send(f"**{random.choice(dice8)}**")
except asyncio.TimeoutError:
await message.delete()
await ctx.send("Procces has been canceled because you didn't answer in **30** second!")
def check10(m):
return m.author == ctx.author and m.content == "10"
try:
await client.wait_for('message', check=check10, timeout=30.0)
coming = await ctx.send("Here it comes...")
time.sleep(1)
await coming.delete()
await ctx.send(f"**{random.choice(dice10)}**")
except asyncio.TimeoutError:
await message.delete()
await ctx.send("Procces has been canceled because you didn't answer in **30** second!")
def check12(m):
return m.author == ctx.author and m.content == "12"
try:
await client.wait_for('message', check=check12, timeout=30.0)
coming = await ctx.send("Here it comes...")
time.sleep(1)
await coming.delete()
await ctx.send(f"**{random.choice(dice12)}**")
except asyncio.TimeoutError:
await message.delete()
await ctx.send("Procces has been canceled because you didn't answer in **30** second!")
def check20(m):
return m.author == ctx.author and m.content == "20"
try:
await client.wait_for('message', check=check20, timeout=30.0)
coming = await ctx.send("Here it comes...")
time.sleep(1)
await coming.delete()
await ctx.send(f"**{random.choice(dice20)}**")
except asyncio.TimeoutError:
await message.delete()
await ctx.send("Procces has been canceled because you didn't answer in **30** second!")
当我键入命令并选择数字 4 时,我的命令确实有效,但当我尝试另一个数字(例如 6)时,它不起作用。我究竟做错了什么?请帮忙。