简体   繁体   English

如何在 dicord.py 中使用 wait_for()?

[英]How to use wait_for() in dicord.py?

I am working on a music bot for discord.我正在开发一个用于不和谐的音乐机器人。 I want to use bot.wait_for() to wait until voice.stop() .我想使用bot.wait_for()等到voice.stop() ie i want the bot to wait until the playback is stopped.即我希望机器人等到播放停止。 I do not want to use the command voice.play(discord.FFmpegPCMAudio(audio), after=lambda e: some_commmand_here) as this command executes a command after the playback is finished.我不想使用命令voice.play(discord.FFmpegPCMAudio(audio), after=lambda e: some_commmand_here)因为此命令在播放完成后执行命令。 However I am trying to make the bot wait until the playback is finished and then do something.但是我试图让机器人等到播放完成然后做一些事情。 I tried bot.wait_for(voice.stop()) which turned out to be wrong.我试过bot.wait_for(voice.stop())结果证明是错误的。 Any help?有什么帮助吗? If bot.wait_for() cannot do the job, any alternative command that waits until the playback is finished is fine with me.如果bot.wait_for()不能完成这项工作,任何等待播放完成的替代命令对我来说都很好。

As far as I know, you can only use these events without on_ prefix for wait_for .据我所知,你只能在没有on_前缀的情况下使用wait_for 这些事件。 So there is only one event related to voice and that is on_voice_state_update .所以只有一个与语音相关的事件,那就是on_voice_state_update So it's not possible to do with api unless you make it yourself.因此,除非您自己制作,否则无法使用 api。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM