Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

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

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...)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...