当我被要求删除角色时,我正在尝试为我的机器人创建各种确认消息。我正在使用wait_for()
函数来实现这一点。但是,即使我一直强迫检查返回true,它似乎永远卡住。 check()
中的print语句也不会运行。唯一运行的打印是第一个打印“请在检查之前先做点事情”的打印。我已经被这个问题困扰了好几天了,我问的每个人都无法弄清楚这个问题。
@bot.command(name='deleteChar', help='!deleteChar {character name}, deletes an existing character')
async def delchar(ctx, name):
for x in character_list:#finds the user's character
if x.user_id == ctx.author.id and x.name == name:
character = x
break
if character == None:#character not found
response = 'character not found'
await ctx.send(response)
return
response = 'Are you sure you want to delete ' + character.name +'? Type y or n.'
await ctx.send(response)
print("please do something before the check")
def check(m):
print("entered check")
#return m.author == ctx.author and m.channel == ctx.channel
return True
try:
msg = await client.wait_for('message', check=check)
except asyncio.TimeoutError:
print("exception caught")
return
await ctx.send("please do something after wait_for")
print("please do something after wait_for")
if msg.content == 'y' or msg.content == 'Y':
await ctx.send(character.name + ' deleted')
elif msg.content == 'n' or msg.content == 'N':
await ctx.send('character not deleted')
else:
await ctx.send('invalid argument')
print("please do something")
更新:我已经从本文档https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#bot复制并改编了wait_for()
的示例代码,以使用@bot
而不是@client
,甚至遇到了同样的问题