首页 > 解决方案 > 检查 wait_for_message 是否来自某个用户并输入某个消息

问题描述

我正在尝试执行一个命令,询问命令中提到的用户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')

标签: python-3.xdiscord.py

解决方案


就像@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')

推荐阅读