gpt4 book ai didi

python - 不和谐机器人在哪里可以找到 ffmpeg buildpack heroku

转载 作者:行者123 更新时间:2023-12-04 22:52:56 27 4
gpt4 key购买 nike

我正在制作一个机器人,它将一个 mp3 文件输出到与 discord.py 的语音聊天中,它通过以下方式在本地工作:vc.play(discord.FFmpegPCMAudio(executable="ffmpeg/bin/ffmpeg.exe", source=noise.mp3))但是我现在将它托管在 Heroku 上,我已经安装了 buildpack,但是我的代码如何访问它来替换上面的代码

最佳答案

您没有包含您的代码,所以我不知道您是否希望它在您在不和谐中编写命令时或当机器人准备好 时播放它,所以我决定在它准备好时让机器人播放(如果你想要它要加入命令,您可以修改我的代码)。另外,我认为如果您为此使用 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/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

  • 并检查您的 requirements.txt 中是否包含所有这些:
  • youtube_dl
  • discord.py[语音]
  • ffmpeg
  • PyNaCl
  • 关于python - 不和谐机器人在哪里可以找到 ffmpeg buildpack heroku,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63283510/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com