【发布时间】:2021-05-25 08:36:05
【问题描述】:
我正在尝试发出一个命令,您可以在其中捕捉凤凰,并随机对您和会员进行 ping 操作,如果您输入 catch,它会在您的计数器上加一分。但是我试过了,最远的是它让我们输入catch。当我输入catch 时它没有响应。
@client.command(aliases=["ctp", "capturethephoenix"])
async def catchthephoenix(ctx, member : discord.Member=None):
points = {ctx.author: 0, member: 0}
random_time = random.randrange(30)
if member == None:
await ctx.send(f"{ctx.author.mention}, You need to mention a member to play with.")
if member == client.user:
await ctx.send(f"{ctx.author.mention}, Hey! Are you trying to catch me??! Mention someone else.")
if member.bot == True:
await ctx.send(f"{ctx.author.mention}, You can't play with a bot.")
else:
game = True
await ctx.send(f"{ctx.author.mention} and {member.mention}, I will alert you when a phoenix is found so you can catch it.")
def check(m):
return m.author.id == ctx.author.id
while True:
try:
message = await client.wait_for('message', check=check, timeout=45)
await asyncio.sleep(random_time)
await ctx.send(f"{ctx.author.mention} and {member.mention}, A Phoenix has been found! Type `catch` to catch it!")
if message.author.id == member.id and message.content.lower() == "catch":
points[member] += 1
await ctx.send(f"{member.name} has caught the phoenix! They have **{points[member]}** point(s)!")
elif message.author.id == ctx.author.id and message.content.lower() == "catch":
points[ctx.author] += 1
await ctx.send(f"{ctx.author.name} has caught the phoenix! They have **{points[ctx.author]}** point(s)!")
except:
game = False
embed = discord.Embed(
color = embed_color,
title = "Game Over",
description = "No one caught the Phoenix in time so the game is over. Final Scores Below.")
embed.add_field(name = f"{member.name}'s score", value = f"{points[member]}")
embed.add_field(name = f"{ctx.author.name}'s score", value = f"{points[ctx.author]}")
await ctx.send(embed=embed)
【问题讨论】:
-
请澄清您所说的“它没有响应”是什么意思。有错误吗?您是否尝试过任何调试来确定代码无法按预期运行的确切位置?
-
当我输入 catch 时,机器人没有响应,也没有错误。这是发生的事情的图片。 imgur.com/a/5U5Pe8a
标签: python python-3.x discord.py