python - Discord.py bot 中断 mp3
问题描述
由于 mp3 文件较长,机器人停止,尝试将比特率更改为低。这是代码
@client.command(pass_context=True)
async def bock(ctx):
await ctx.message.delete()
author = ctx.message.author
channel = author.voice.channel
voice = get(client.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
voice.play(discord.FFmpegPCMAudio(executable=FFMexec, source="bock.mp3"))#, options = "-analyzeduration 1000000000 -i"
while voice.is_playing():
time.sleep(0.5)
await voice.disconnect()
解决方案
async def bock(ctx):
await ctx.message.delete()
author = ctx.message.author
channel = author.voice.channel
voice = get(client.voice_clients, guild=ctx.guild)
if voice and voice.is_connected():
await voice.move_to(channel)
else:
voice = await channel.connect()
voice.play(discord.FFmpegPCMAudio(executable=FFMexec, source="bock.mp3"))#, options = "-analyzeduration 1000000000 -i"
while voice.is_playing():
await asyncio.sleep(5) # bot was frozen to death before
await voice.disconnect()
现在可以用了,谢谢解答
推荐阅读
- matlab - 在 MATLAB 中添加的路径似乎没有添加
- ssh - 使用 SSH 在 Azure Pipeline 中签出 git 子模块
- html - Angular Material底页,尝试将变量作为数据传递时遇到问题
- c - 获取超出范围的数组元素的地址是未定义的行为吗?
- python - 当文件夹路径包含“#”时,绘图在非默认 .html 查看器中打开
- regex - 匹配两个单独文本的正则表达式,也忽略其间的所有内容
- vim - Vim 中丢失的语法高亮显示,但仅限于某个文件名
- ansible - 两个ansible sesu成为任务生成错误
- spotfire - Spotfire 数据表 - 当 [Column] != "Value" 时通过表达式限制按需数据
- php - 减少用于二进制比较的 UTF-8 字符串