discord.py wait_for永远卡住了

问题描述

当我被要求删除角色时,我正在尝试为我的机器人创建各种确认消息。我正在使用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,甚至遇到了同样的问题

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...