python-3.x - 检查 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')
解决方案
就像@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')
推荐阅读
- aws-lambda - AWS Lambda JSON 响应的 WSO2 响应消息中介引发 XMLStreamException
- arrays - 创建一个 Excel 公式数组
- maven - Micronaut Swagger..无法呈现此定义
- python - 如何在没有numpy的情况下沿python中列表的轴取平均值?
- python - Kedro 条件管道(或替代方法)
- compilation - 如何修复 Jmodelica 编译错误?
- php - caldav yahoo:报告忙忙查询导致 500 服务器错误
- python - kmeans 聚类 python
- dart - 如何向 dart js 外观添加扩展
- swift - 为什么视图修饰符不能接受不可变变量?