![](/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.