dischord .py ffmpeg我已经正确设置了一切,它是下载和播放文件,我需要帮助更改安装文件的目录,代码如下:



我设置正确,它做了我需要的一切播放,暂停,恢复等。我甚至在谷歌上都找不到如何更改下载文件的目录。我只是想让它不下载。py文件的主目录中的文件,而是将它们下载到一个单独的文件夹中,这样它就可以更有组织。谢谢你的帮助。

import youtube_dl
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' # bind to ipv4 since ipv6 addresses cause issues sometimes
}
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:
# take first item from a playlist
data = data['entries'][0]
filename = data['url'] if stream else ytdl.prepare_filename(data)
return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)
@client.command(aliases=['p'])
@commands.has_role('DJ')
async def play(ctx, url):
channel = ctx.message.author.voice.channel
server = ctx.message.guild
author=ctx.message.author
guild=ctx.message.guild
voice=discord.utils.get(client.voice_clients,guild=ctx.guild)
if voice==None:
await channel.connect()
embed=discord.Embed(title='Connected',description=f'{author.mention} I have Joined Channel {channel.mention}',colour=discord.Colour.green())
await ctx.send(embed=embed)
channel_2=893855384517873725
audit_channel=client.get_channel(channel_2)
embed=discord.Embed(title='zenabz Bot Log',description=f'{author.mention} Has Requested Bot to Join Channel {channel.mention}',colour=discord.Colour.random())
await audit_channel.send(embed=embed)
print(f'{author} Has Requested Bot to Join Channel {channel}')
async with ctx.typing():
voice_channel = server.voice_client
player = await YTDLSource.from_url(url, loop=client.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send(f'{author.mention} **Now playing:** {format(player.title)}')
embed=discord.Embed(title='zenabz Bot Log',description=f'{author.mention} Has Requested Bot to play: {format(player.title)}',colour=discord.Colour.random())
await audit_channel.send(embed=embed)
print(f'{author} Has Requested Bot to to play: {format(player.title)}')

async with ctx.typing():
voice_channel = server.voice_client
player = await YTDLSource.from_url(url, loop=client.loop)
voice.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send(f'{author.mention} **Now playing:** {format(player.title)}')
channel_2=893855384517873725
audit_channel=client.get_channel(channel_2)
embed=discord.Embed(title='zenabz Bot Log',description=f'{author.mention} Has Requested Bot to play: {format(player.title)}',colour=discord.Colour.random())
await audit_channel.send(embed=embed)
print(f'{author} Has Requested Bot to to play: {format(player.title)}')
@play.error
async def play_error(ctx,error):
print(error)
if isinstance(error, commands.MissingRole):
author=ctx.message.author
embed=discord.Embed(title="Missing 'DJ' Role",description=f"{author.mention} you don't have the required roles to use this command", colour=discord.Colour.red())
ctx.send(embed=embed)

对不起,我不知道如何更改下载目录,但是,

ytdl_format_options = {
'format': 'bestaudio/best',
'extractaudio': True,
'audioformat': 'mp3',
'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' # bind to ipv4 since ipv6 addresses cause issues sometimes
}

这个配置不会下载并保存视频到你的目录,而是提取音频并播放。

相关内容

  • 没有找到相关文章

最新更新