discord.py 重写 |获取作者消息的问题
discord.py rewrite | Problem with getting author message
我一直在我的服务器中制作数字游戏命令,有人建议我添加难度。所以,我有 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" 回复聊天机器人时,我没有收到任何回复。
我在尝试修复它时为除我以外的所有人禁用了该命令,但我不知道如何开始。
非常感谢您的回答,因为我自己没有看到解决方案,谢谢!
[我没有展示实际的数字游戏,因为它无关紧要而且很长]
只需创建一个新的检查函数来执行您想要的操作。
def abc_check(author):
def inner_check(message):
return author == message.author and message.content in ('a', 'b', 'c')
return inner_check
我一直在我的服务器中制作数字游戏命令,有人建议我添加难度。所以,我有 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" 回复聊天机器人时,我没有收到任何回复。 我在尝试修复它时为除我以外的所有人禁用了该命令,但我不知道如何开始。
非常感谢您的回答,因为我自己没有看到解决方案,谢谢! [我没有展示实际的数字游戏,因为它无关紧要而且很长]
只需创建一个新的检查函数来执行您想要的操作。
def abc_check(author):
def inner_check(message):
return author == message.author and message.content in ('a', 'b', 'c')
return inner_check