Сделал бота для дискорд сервера, но он не работает
server, server_id, name_channel = None, None, None
domains = \['https://www.youtube.com/', 'http://www.youtube.com/', 'https://youtu.be/', 'http://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, server_id, name_channel
author = ctx.author
if command == None:
server = ctx.guild
name_channel = author.voice.channel.name
voice_channel = disnake.utils.get(server.voice.channels, name = name_channel)
params = command.split(' ')
if len(params) == 1:
source = params\[0\]
server = ctx.guild
name_channel = author.voice.channel.name
voice_channel = disnake.utils.get(server.voice.channels, name = name_channel)
print('param 1')
elif len(params) == 3:
server_id = params\[0\]
voice_id = params\[1\]
source = params\[2\]
try:
server_id = int(server_id)
voice_id = int(voice_id)
except:
await ctx.channel.send(f'{author.mention}, id серверу або голосового каналу повинне бути чилочисленним!')
return
print('param 3')
server = bot.get_guild(server_id)
voice_channel = disnake.utils.get(server.voice_channels, id=voice_id)
else:
await ctx.channel.send(f'{author.mention} команда не правильна!')
return
voice=disnake.utils.get(bot.voice_clients, guild = server)
if voice is None:
await voice_channel.connect()
voice = disnake.utils.get(bot.voice_clients, guild = server)
if source == None:
pass
elif source.startswith('http'):
if not check_domains(source):
await ctx.channel.send(f'{author.mention}ссилка не являється дозволеною')
return
sound_there = os.path.isfile('/sound.mp3')
try:
if sound_there:
os.remove('/sound.mp3')
except PermissionError:
await ctx.channel.send('Немає прав для видалення файлу')
return
ydl_opts = {
'format': 'bestaudio/best',
'postproccessors' : \[
{
'key': 'FFmepgExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}
],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(\[source\])
for file in os.listdir('./'):
if file.endswith('.mp3'):
os.rename(file, 'song.mp3')
voice.play(disnake.FFmpegPCMAudio('sound.mp3'))
else:
voice.play(disnake.FFmpegPCMAudio(f'{source}'))
Если нужно будет что-то дополнить, отпишите
