我一直在服务器中执行数字游戏命令,有人建议我加点困难。因此,我有3个困难供用户选择。 我已经有一些代码可以引起作者的响应并且可以正常工作,所以我在代码中重新使用了它,现在我很困惑。它可能非常明显,但我找不到它:
@client.command(name='numgame',
brief='Guess a number between 1 and 100',
pass_ctx=True)
async def numgame(ctx):
if ctx.author.id != 368442355382222849:
await ctx.send('Command currently disabled')
return
await ctx.send('Difficulties: a] 1-10 b] 1-50 c] 1-100')
msg = await client.wait_for('message', check=check(ctx.author), timeout=30)
diff = str(msg.content)
if diff == 'a':
max = 10
number = random.randint(1,10)
await ctx.send('You have 5 guesses')
await ctx.send('Pick a number between 1 and 10')
elif diff == 'b':
max = 50
number = random.randint(1,50)
await ctx.send('You have 5 guesses')
await ctx.send('Pick a number between 1 and 50')
elif diff == 'c':
max = 100
number = random.randint(1,100)
await ctx.send('You have 5 guesses')
await ctx.send('Pick a number between 1 and 100')
else:
ctx.send('Please try the command again...')
return
msg = None
这是我正在使用的支票:
def check(author):
def inner_check(message):
# author check
if message.author != author:
return False
# inner check
try:
int(message.content)
return True
except ValueError:
return False
当我用“ a”,“ b”或“ c”回复聊天机器人时,没有任何响应。 在尝试修复该命令时,我为我以外的所有人禁用了该命令,但我不知道如何启动。
我希望得到一个答案,因为我自己看不到解决方案,谢谢! [我没有显示实际的数字游戏,因为它无关紧要且冗长]
答案 0 :(得分:1)
只需创建一个新的检查函数即可执行所需的操作。
def abc_check(author):
def inner_check(message):
return author == message.author and message.content in ('a', 'b', 'c')
return inner_check