在进程结束之前两次使用命令时出错[Discord.py Rewrite]



这是我的石头剪刀代码。如果游戏正在进行中,有人或你自己使用了该命令,则会出现一个错误,机器人会不断发送信息:"你的选择是什么?"?(r( ock、(p(aper、(s(cissors或(q(uit’

我如何才能摆脱垃圾邮件"你的选择是什么?"?(r( ock,(p(aper,(s(cissors还是(q(uit?

@client.command(pass_context=True, aliases=['rps'])
@commands.guild_only()
async def game(ctx):
await ctx.send(
'Hello, ' + ctx.message.author.mention + '? Wanna play a round of Rock, Paper, Scissors?')
wins = 0
losses = 0
ties = 0
while True:
await ctx.send('%s Wins, %s Losses, %s Draws n' % (wins, losses, ties))
while True:
await ctx.send('What is your choice? (r)ock, (p)aper, (s)cissors or (q)uit')  
player = await client.wait_for('message') 
print(str(player))
if player.content == 'q':
await ctx.send('Game succesfully quitted.')
return
if player.content == 'r' or player.content == 'p' or player.content == 's':
break
if player.content == 'r':
await ctx.send('Rock against...')
elif player.content == 'p':
await ctx.send('Paper against...')
elif player.content == 's':
await ctx.send('Scissors against...')
randomnum = random.randint(1, 3)
if randomnum == 1:
computer = 'r'
await ctx.send('Rock!')
elif randomnum == 2:
computer = 'p'
await ctx.send('Paper!')
elif randomnum == 3:
computer = 's'
await ctx.send('Scissors!')
if player.content == computer:
await ctx.send("It's a Draw!")
ties = ties + 1
elif player.content == 'r' and computer == 's':
await ctx.send('You win!')
wins = wins + 1
elif player.content == 'r' and computer == 'p':
await ctx.send('The bot wins!')
losses = losses + 1
elif player.content == 'p' and computer == 'r':
await ctx.send('You win!')
wins = wins + 1
elif player.content == 'p' and computer == 's':
losses = losses + 1
await ctx.send('The bot wins!')
elif player.content == 's' and computer == 'p':
await ctx.send('You win!')
wins = wins + 1
elif player.content == 's' and computer == 'r':
await ctx.send('The bot wins!')
losses = losses + 1
player = await client.wait_for('message')

您必须在此添加check。

def check(msg, user):
return user.author == ctx.message.author and msg.channel == ctx.channel
player = await client.wait_for('message', check=check())

最新更新