![](/img/trans.png)
[英]Is there a way to use an async check function for discord.py wait_for?
[英]How to use wait_for function in discord.py?
我对 discord.py 很陌生,我想问一下如何使用 wait_for 命令等待上一个命令的作者发送给机器人的消息? 如果这没有意义,我很抱歉。
等待用户回复:
内容复制
@client.event
async def on_message(message):
if message.content.startswith('$greet'):
channel = message.channel
await channel.send('Say hello!')
def check(m):
return m.content == 'hello' and m.channel == channel
msg = await client.wait_for('message', check=check)
await channel.send('Hello {.author}!'.format(msg))
等待消息作者的赞许反应:
content_copy
@client.event
async def on_message(message):
if message.content.startswith('$thumb'):
channel = message.channel
await channel.send('Send me that 👍 reaction, mate')
def check(reaction, user):
return user == message.author and str(reaction.emoji) == '👍'
try:
reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check)
except asyncio.TimeoutError:
await channel.send('👎')
else:
await channel.send('👍')
你应该看看 discord.py 文档,它有一个很好的例子来满足你的需求
无论如何,这就是你的做法
# wait for a message, accept it only if message's author id == command's author id
msg = await bot.wait_for("message", check=lambda m: m.author.id == ctx.author.id)
# get content
msg.content
# get id
msg.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.