如何停止来自一个用户的多个相同命令? (不和谐机器人)

时间:2021-03-04 02:42:18

标签: python command discord.py

我正在运行类似于猜谜游戏的东西,在这个游戏中,你被赋予了界限,我的机器人会告诉你你的猜测是高还是低。我想知道如何阻止用户打开多个游戏? (例如,它会重叠消​​息并变得非常丑陋,我想避免这种情况。)这是我的代码:

             aliases=['gg', 'guessinggame'])
async def guessing_game(ctx, num):
    number = random.randint(0, int(num))
    await ctx.send("Game started!")
    num_of_tries = 0
    user = ctx.author.id
    await ctx.send('Take a guess.')
    while True:
        response = await bot.wait_for('message')
        currentsender = response.author.id
        if currentsender != user or currentsender == bot.user.id:
            continue
        # if not response.content.lower().startswith('b&'):
        #     continue
        if response.content == "stop bot pls":
            await ctx.send(f'Stopped game, {response.author.mention}')
            return
        if not response.content.isdigit():
            continue
        num_of_tries += 1
        guess = int(response.content)
        if guess < number:
            await ctx.send(f'My number is larger, {response.author.mention}.')
            await ctx.send('Take a guess.')
        elif guess > number:
            await ctx.send(f'My number is smaller, {response.author.mention}.')
            await ctx.send('Take a guess.')
        else:
            await ctx.send(f'Hey, {response.author.mention}, you got it! (with {num_of_tries} tries)')
            return

0 个答案:

没有答案