python - 不和谐机器人在哪里可以找到 ffmpeg buildpack heroku
问题描述
我正在制作一个机器人,它将一个 mp3 文件输出到与 discord.py 的语音聊天中,它通过以下方式在本地工作:
vc.play(discord.FFmpegPCMAudio(executable="ffmpeg/bin/ffmpeg.exe", source=noise.mp3))
但是我现在将它托管在 Heroku 上,我已经安装了 buildpack,但是我的代码如何访问它来替换上面的代码
解决方案
您没有包含您的代码,所以我不知道您是否希望它在您在 discord 中编写命令或机器人准备好时播放,所以我决定让机器人在准备好时播放(如果您希望它加入在命令上你可以修改我的代码)。另外,我认为如果您为此使用youtube_dl会更容易。
import discord
from discord.ext import commands
import youtube_dl
Token = "XXXXXX" #your token
client = commands.Bot(command_prefix = ":")
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
def endSong(guild, path):
os.remove(path)
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ" #link to your song on YouTube
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
file = ydl.extract_info(url, download=True)
guild = "1234567890" #id of your server which you can get by right clicking on server name and clicking "Copy ID" (developer mode must be on)
path = str(file['title']) + "-" + str(file['id'] + ".mp3")
channel = client.get_channel(1234567890) #id of your channel (you get it like server id, but by right clicking on channel)
voice_client = await channel.connect()
voice_client.play(discord.FFmpegPCMAudio(path), after=lambda x: endSong(guild, path))
voice_client.source = discord.PCMVolumeTransformer(voice_client.source, 1)
while voice_client.is_playing(): #waits until song ends
await asyncio.sleep(1)
else:
await voice_client.disconnect() #and disconnects
print("Disconnected")
还要记住在 Heroku 上包含 4 个构建包,以确保一切正常(Your APP > Settings > Buildpacks
):
- Heroku/蟒蛇
- https://github.com/heroku/heroku-buildpack-apt.git
- https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
- https://github.com/xrisk/heroku-opus.git
并检查您的requirements.txt中是否包含所有这些:
- 点子
- youtube_dl
- discord.py[语音]
- ffmpeg
- 氯化钠
推荐阅读
- css - How to use next-css in next.config.js in combination with custom server Express
- c# - 我可以使用内存中实体框架 6.2.0 还是有任何方法可以做到这一点
- java - 如何防止 Spring 创建一个只是要扩展的“抽象”泛型类型存储库?
- java - Is there any method after creating the view of fragments?How to change Layout of tabs after creating fragments
- c# - Reading from file with different line length
- dart - 当 Flutter 的 TabBar 被点击时移除高亮
- javascript - 为什么 console.log() 不连接字符串?
- javascript - 将由点分隔的 int 字符串转换为 char 字符串
- amazon-web-services - handling dynamo db read and write units
- java - Android Studio app stops when location is accessed from fire base