我正在尝试制作一个简单的Discord音乐机器人,但目前由于这个问题而停滞不前。问题在于,每次我尝试通过youtube_dl库播放音乐时,它会弹出提示:“未找到ffmpeg”。
这是main.py文件:
import discord
import os
import asyncio
import youtube_dl
import ffmpeg
token = 'NzY5NTUzNDcwNjAwMTE4Mjgz.G3Dzce.XYKNAyLfBPg0ug5XPKssV-9EvsFjBlCMeM43ag'
client = discord.Client()
block_words = ['dick', 'nigga', 'ujku shijakut', 'arli', 'http://', 'https://']
voice_clients = {}
yt_dl_opts = {'format': 'bestaudio/best'}
ytdl = youtube_dl.YoutubeDL(yt_dl_opts)
ffmpeg_options = {'options': '-vn'}
@client.event
async def on_ready():
print(f'Bot has logged in as {client.user}')
@client.event
async def on_message(msg):
if msg.author != client.user:
if msg.content.lower().startswith('?hi'):
await msg.channel.send(f'Hi, {msg.author.display_name}')
@client.event
async def on_message(msg):
if msg.author != client.user:
for text in block_words:
if "OTR" not in str(msg.author.roles) and text in str(msg.content.lower()):
await msg.delete()
return
print("Not Deleting...")
@client.event
async def on_message(msg):
if msg.content.startswith('?play'):
try:
url = msg.content.split()[1]
voice_client = await msg.author.voice.channel.connect()
voice_clients[voice_client.guild.id] = voice_client
loop = asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=False))
song = data['url']
player = discord.FFmpegPCMAudio(song, **ffmpeg_options)
except Exception as err:
print(err)
client.run(token)
apt install ffmpeg
。 - W00dy