Discord.py-rewrite wait_for() how do i use?

青春壹個敷衍的年華 提交于 2020-08-19 12:59:52

问题


I can not really use wait_if () the way I want it, can anyone explain how to use wait_for ('message') and wait_for ('reaction'), only by the user of the command? (message translated by Google Translate, forgive me for any error...)


回答1:


wait_for takes a check argument that is a function that takes the arguments of the event you're waiting for and determines whether or not that is the event you're waiting for.

For example, the on_message event takes a message argument, so if we wanted to check the author of a message we could do:

msg = await client.wait_for('message', check=lambda message: message.author == ctx.author)

to see that the new message comes from the same person who invoked the currently running command.

If we wanted to send a message to the next person to react with a certain emoji, we could do

reaction, user = await client.wait_for('reaction_add', 
                                       check=lambda reaction, user: reaction.emoji == '👍')
await user.send("👍 to you too!")


来源:https://stackoverflow.com/questions/52571844/discord-py-rewrite-wait-for-how-do-i-use

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!