Решил написать дискорд-бота который может воспроизводить музыку,но когда написал код и запустил его, то в консоли увидел 'await' outside function
код:
from discord.utils import get
from discord.ext import commands
import youtube_dl
import os
client = commands.Bot(command_prefix = '')
@client.event
async def on_ready():
print( 'Я работаю' )
@client.command()
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] У тебя нет прав для исполнения этой команды')
await ctx.send('Пожалуйста,ожидайте')
voice = get(client.voice_clients, guild = ctx.guild)
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('.mp3'):
name = FileExistsError
print('[log] переиминовываю файл: {file}')
os.rename(file, 'song.mp3')
voice.play(discord.FFmpegPCMAudio('song.mp3'), after = lambda e: print(f'[log] ладно'))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.volume = 0.07
song_name = name.rsplit('-', 2)
await ctx.send(f'Играем музяка: {song_name[0]}')
ошибка:
File "c:/Users/79099/Desktop/server/bot.py", line 53 await ctx.send(f'Играем музяка: {song_name[0]}') ^ SyntaxError: 'await' outside function