python - Discord.py 循环播放音频源
问题描述
有谁知道如何在 FFmpeg 中循环相同的源代码?
这是我的代码:
@bot.command(pass_context = True)
async def join(ctx):
if (ctx.author.voice):
channel = ctx.message.author.voice.channel
voice = await channel.connect()
source = FFmpegPCMAudio('test.mp3')
player = voice.play(source)
else:
await ctx.send('You need to be in a Voice-Channel.')
我想要永久循环播放音频文件“test.mp3”。我在互联网上搜索过,但那里给出的所有结果都已过时。
解决方案
这是一种知道歌曲何时播放完毕的方法。
if (ctx.author.voice):
finished = False
channel = ctx.message.author.voice.channel
voice = await channel.connect()
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e: finished = True)
使用 lambda 函数,您可以实现循环结构以在完成后重播歌曲。
推荐阅读
- php - 动态抓取最新帖子 OctoberCMS 博客插件
- android - Error when trusting HTTPS certificate using okhttp in Kotlin
- git - 有没有办法在不增加任何版本的情况下使用 lerna 推送 git 标签?
- java - 如何在 JMeter 中使用 Java 代码生成一些 HKSTD id ?此 id 将在进一步的 http 请求采样器中使用
- c# - 在没有任何类修改的情况下绑定 object.object.prop
- machine-learning - ValueError:发现样本数量不一致的输入变量:[559, 140]
- vuejs2 - Vue js:模态组件上的道具不断显示typeError
- mysql - SQL 表中的唯一交叉联接
- powershell - Remove-Item 在 Powershell 脚本中不起作用
- wordpress - Wordpress 更新因内部服务器错误而失败