[log] Загружаю Музику...
[youtube] 7mljFhqOHtE: Downloading webpage
[download] Destination: Duncan Laurence - Arcade (Russian cover)_(кавер на русском)-7mljFhqOHtE.webm
[download] 100% of 2.94MiB in 01:11
[ffmpeg] Destination: Duncan Laurence - Arcade (Russian cover)_(кавер на русском)-7mljFhqOHtE.mp3
Deleting original file Duncan Laurence - Arcade (Russian cover)_(кавер на русском)-7mljFhqOHtE.webm (pass -k to keep)
An exception has occurred while executing command `play`:
Traceback (most recent call last):
File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python36\lib\site-packages\discord_slash\client.py", line 1353, in invoke_command
await func.invoke(ctx, **args)
File "C:\Users\ilbaa\AppData\Local\Programs\Python\Python36\lib\site-packages\discord_slash\model.py", line 210, in invoke
return await self.func(*args, **kwargs)
File "C:\Users\ilbaa\Desktop\Monika.py", line 59, in play
voice.play(discord.FFmpegPCMAudio('song.mp3'), after = lambda e: print(f'[log] {name}, музика закончилась'))
NameError: name 'voice' is not defined
import os
import ffmpeg
import asyncio
import youtube_dl
import discord
import datetime
import json
import requests
import random
from discord.ext import commands
from discord_slash import SlashCommand
Bot = commands.Bot(command_prefix="c:", intents=discord.Intents.all())
slash = SlashCommand(Bot, sync_commands=True)
Bot.remove_command('help')
@slash.slash()
async def play(ctx, url : str):
song_there = os.path.isfile('song.mp3')
try:
if song_there:
os.remove('song.mp3')
print('[log] Старий файл удален')
except PermissionError:
print('[log] Не удалось удалить файл')
ydl_opts ={
'format' : 'bestaudio/best',
'postprocessors' : [{
'key' : 'FFmpegExtractAudio',
'preferredcodec' : 'mp3',
'preferredquality' : '192'
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl :
print('[log] Загружаю Музику...')
ydl.download([url])
for file in os.listdir('./'):
if file.endswith('.webm'):
name = file
print('[log] переименовиваю файл {file}')
os.rename(file, 'song.mp3')
voice.play(discord.FFmpegPCMAudio('song.mp3'), after = lambda e: print(f'[log] {name}, музика закончилась'))
voice.sourse = discord.PCMVolumeTransformer(voice.sourse)
voice.sourse.volume = 0.08
song_name = name.rsplist('-', 2)
await ctx.send(f'Сейчас проигривает музика: {song_name[0]}')