检查wait_for_message是否来自特定用户并键入特定消息

时间:2019-03-08 12:09:49

标签: python-3.x discord.py

我正在尝试执行一条命令,询问诸如sir pls testinput @user之类的命令中提到的用户是否要玩。如果他回答sir pls testinput accept,那么他应该做些什么。

我对此的处理方式是((遗憾的是,该方法不起作用,因为它没有属性content,也可能没有author

@bot.command(pass_context = True)
async def testinput(ctx, user: discord.Member=None):
    await bot.say('Do you want to play {}? If yes type **sir pls testinput accept**.'.format(user.mention))
    response = bot.wait_for_message(author=user, content="sir pls testinput accept", timeout=30)
    if response.content == "sir pls testinput accept" and response.author == user:
        await bot.say('User {} decided to play with you {}'.format(user, ctx.message.author))
    else:
        await bot.say('Debug: Skipped the if statement')

1 个答案:

答案 0 :(得分:0)

就像@Tristo在评论中所说,我忘记在命令前添加await,因为它是协程。

工作命令如下:

@bot.command(pass_context = True)
async def testinput(ctx, user: discord.Member=None):
    await bot.say('Do you want to play {}? If yes type **sir pls testinput accept**.'.format(user.mention))
    response = await bot.wait_for_message(author=user, content="sir pls testinput accept", timeout=30)
    if response.content == "sir pls testinput accept" and response.author == user:
        await bot.say('User {} decided to play with you {}'.format(user, ctx.message.author))
    else:
        await bot.say('Debug: Skipped the if statement')