Проблема в програме Python
У меня вылазит ошибка в ydl.download([sourse]) 85 строка вот код:
# -*- coding: utf = 8 -*-
import discord
from discord.ext import commands
from config import token
import youtube_dl
import os
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print('Я зайшов в систему.')
server, servers_id, name_channel = None, None, None
domains = ['https://www.youtube.com/', 'http://www.youtube.com/', 'https://youtu.be/']
async def check_domains(link):
for x in domains:
if link.startswith(x):
return True
return False
@bot.command()
async def play(ctx, *, command=None):
"""Робить музон"""
global server, servers_id, name_channel
author = ctx.author
if command == None:
server = ctx.guild
name_channel = author.Voice.channel.name
voice_channel = discord.utils.get(server.voice_channels, name=name_channel)
params = command.split(' ')
if len(params) == 1:
sourse = params[0]
server = ctx.guild
name_channel = author.voice.channel.name
voice_channel = discord.utils.get(server.voice_channels, name=name_channel)
print('param 1')
elif len(params) == 3:
server_id = params[0]
voice_id = params[1]
sourse = params[2]
try:
server_id = int(server_id)
voice_id = int(voice_id)
except:
await ctx.chanel.send(f'{author.mention}, id сервера або войса має бути цілим числом.')
return
print('param 3')
server = bot.get_guild(server_id)
voice_channel = discord.utils.get(server.voice.channels, id=voice_id)
else:
await ctx.channel.send(f'{author.mention}, команда не коректна.')
return
voice = discord.utils.get(bot.voice_clients, guild=server)
if voice is None:
await voice_channel.connect()
voice = discord.utils.get(bot.voice_clients, guild=server)
if sourse == None:
pass
elif sourse.startswith('https'):
if not await check_domains(sourse):
await ctx.channel.send(f'{author.mention}, cилка не доступна.')
return
song_there = os.path.isfile('song.mp3')
try:
if song_there:
os.remove('song.mp3')
except PermissionError:
await ctx.channel.send('Не достатньо прав.')
return
ydl_opts = {'format': 'bestaudio/best',
'postprocessors': [
{'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192', }
], }
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([sourse])
for file in os.listdir('./'):
if file.endswith('.mp3'):
name = file
os.rename(file, 'song.mp3')
voice.play(discord.FFmpegPCMAudio('song.mp3'))
else:
voice.play(discord.FFmpegPCMAudio(f'{sourse}'))
@bot.command()
async def leave(ctx):
global server, name_channel
voice = discord.utils.get(bot.voice_clients, guild=server)
if voice.is_connected():
await voice.disconnect()
else:
await ctx.channel.send(f'{ctx.author.maintion}, бот уже вийшов.')
@bot.command()
async def pause(ctx):
voice = discord.utils.get(bot.voice_clients, guild=server)
if voice.is_plaing():
voice.pause()
else:
await ctx.channel.send('Бот уже на паузі.')
@bot.command()
async def resume(ctx):
voice = discord.utils.get(bot.voice_clients, guild=server)
if voice.is_paused():
voice.resume()
else:
await ctx.channel.send('Музика уже грає.')
@bot.command()
async def stop():
voice = discord.utils.get(bot.voice_clients, guild=server)
voice.stop()
bot.run(token)
Буду очень благодарен если поможете