Where can discord bots find the ffmpeg buildpack heroku
You didn't include your code, so I didn't know if you want it to play when you write command in discord or when the bot is ready, so I decided to make bot play when it's ready (if you want it to join on the command you can modify my code). Also, I think it will be easier if you use youtube_dl for this.
import discordfrom discord.ext import commandsimport youtube_dlToken = "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 YouTubewith 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")
Also remember to include 4 buildpacks on Heroku to make sure everything will work (Your APP > Settings > Buildpacks
):
- heroku/python
- https://github.com/heroku/heroku-buildpack-apt.git
- https://github.com/jonathanong/heroku-buildpack-ffmpeg-latest.git
- https://github.com/xrisk/heroku-opus.git
And check if you have all of these in your requirements.txt:
- pip
- youtube_dl
- discord.py[voice]
- ffmpeg
- PyNaCl