如何让Discord机器人的ffmpeg.exe在Discloud云托管平台正常运行?
解决Discloud托管Discord机器人时FFmpeg路径错误问题
问题原因
- Discloud采用Linux服务器环境,你代码中硬编码的是Windows本地的FFmpeg路径,Linux系统不存在该路径
- Discloud平台默认预装了FFmpeg,无需手动上传或指定Windows格式的路径
修复后的代码
删除代码中指定Windows本地FFmpeg路径的executable参数,直接使用系统预装的FFmpeg:
@bot.command(name='play', help='To play song') async def play(ctx, url): voice_channel = ctx.author.voice.channel if voice_channel is None: return await ctx.send('You are not connected to a voice channel.') async with ctx.typing(): filename = await YTDLSource.from_url(url, loop=bot.loop) if ctx.voice_client is not None: ctx.voice_client.stop() # 移除Windows本地的executable参数,使用系统预装的ffmpeg source = discord.FFmpegPCMAudio(source=filename) voice_channel.play(source) await ctx.send('**Now playing:** {}'.format(filename))
补充说明
如果需要给FFmpeg添加额外参数(比如禁用视频流),可以直接通过args参数配置,无需指定executable路径:
source = discord.FFmpegPCMAudio(source=filename, args=['-vn'])
内容的提问来源于stack exchange,提问作者Sc4rl3ttfir3
相关产品推荐
相关产品推荐

