我一直在尝试解决一个问题,同时使用 discord py 创建音乐命令。除了一个命令外,每个命令都可以正常工作。当我尝试使用 play 命令时,出现以下错误:
错误:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: ffmpeg was not found.
代码(仅包括播放命令,其他命令与本主题无关,它们工作正常):
import discord
from discord.ext import commands, tasks
from discord.voice_client import VoiceClient
import youtube_dl
import random
youtube_dl.utils.bug_reports_message = lambda: ''
ytdl_format_options = {
'format': 'bestaudio/best',
'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
'restrictfilenames': True,
'noplaylist': True,
'nocheckcertificate': True,
'ignoreerrors': False,
'logtostderr': False,
'quiet': True,
'no_warnings': True,
'default_search': 'auto',
'source_address': '0.0.0.0'
}
ffmpeg_options = {
'options': '-vn'
}
ytdl = youtube_dl.YoutubeDL(ytdl_format_options)
class YTDLSource(discord.PCMVolumeTransformer):
def __init__(self, source, *, data, volume=0.5):
super().__init__(source, volume)
self.data = data
self.title = data.get('title')
self.url = data.get('url')
@classmethod
async def from_url(cls, url, *, loop=None, stream=False):
loop = loop or asyncio.get_event_loop()
data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))
if 'entries' in data:
data = data['entries'][0]
filename = data['url'] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)
status = ['Jamming!', 'Eating!', 'Sleeping!']
queue = []
@bot.command(name='gplay', help='Playing the song.')
async def gplay(ctx):
global queue
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
player = await YTDLSource.from_url(queue[0], loop=bot.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send('**Now playing** {}'.format(player.title))
del (queue[0])
答案 0 :(得分:-1)
好的,经过一番搜索后,我发现重新启动计算机应该可以解决问题并且它起作用了。对于曾经遇到同样问题的其他人,我推荐这个视频:https://www.youtube.com/watch?v=r1AtmY-RMyQ&ab_channel=TroubleChute