#python #discord.py #discord.py-rewrite
#python #discord.py
Вопрос:
Это мой код «камень, ножницы, бумага». Если игра продолжается и кто-то или вы сами используете команду, возникнет ошибка, при которой бот будет продолжать рассылать спам-сообщение: «Каков ваш выбор? (r) ock, (p) aper, (s) cissors или (q) uit’
Как я могу избавиться от спама «Каков ваш выбор? (r) окк, (p) апер, (s) сиссоры или (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
Ответ №1:
player = await client.wait_for('message')
вы должны добавить проверку в это.
def check(msg, user):
return user.author == ctx.message.author and msg.channel == ctx.channel
player = await client.wait_for('message', check=check())