首页 > 解决方案 > 如何从一个用户停止多个相同的命令?(不和谐机器人)

问题描述

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

             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

标签: pythoncommanddiscord.py

解决方案


推荐阅读