python - 如何从一个用户停止多个相同的命令?(不和谐机器人)
问题描述
我正在运行类似于猜谜游戏的游戏,在游戏中你被赋予了界限,我的机器人会告诉你你的猜测是更高还是更低。我想知道如何阻止用户打开多个游戏?(例如,它会重叠消息并变得非常丑陋,我想避免这种情况。)这是我的代码:
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
解决方案
推荐阅读
- html - 为什么我不能更改下拉图标?
- express - 如何在渲染前访问 nextServerInit 中的 req.session
- c# - 无法按下 Angular 表单的按钮
- python - 关于 Juypter 笔记本错误的模块 squarify
- xna - Monogame 中的像素完美碰撞,具有浮动位置
- django - 在 def clean() 上设置字段特定错误时出现 KeyError
- r - r:通过在 dplyr 中将它们作为列表传递来编译 excel 文件
- git - 在 Git 的术语中,`origin` 是 ref 还是别的什么?
- php - 循环 JSON 数据仅显示第一个字符
- ssl - kong-ingress-controller:GKE 中的入口错误