Я пытаюсь создать бота, который воспроизводит видео.
Я уже реализовал команды join
и leave
для своего бота (для голосовых каналов), но, похоже, не понимаю для воспроизведения видео. Я попытался поместить его в свой основной файл бота, и он отлично работает, но я хочу сделать его винтиком, чтобы он был отдельной категорией в команде справки, и я не могу понять это.
Он загрузил песню, и все выглядит нормально, но он просто не воспроизводит видео и показывает мне ошибку.
Это код моего бота:
@bot.command(pass_context=True, aliases=["p"])
async def play(self,ctx, url: str):
song_there = os.path.isfile("song.mp3")
try:
if song_there:
os.remove("song.mp3")
print("Removed old song file")
except PermissionError:
print("Trying to delete song file, but its being played.")
await ctx.send("ERROR: Music playing.")
return
await ctx.send("Getting everything ready...")
voice = get(bot.voice_clients, guild=ctx.guild)
ydl_opts = {
'format': 'bestaudio/best',
'default_search': 'auto',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
print("Downloading audio now\n")
ydl.download([url])
for file in os.listdir("./"):
if file.endswith(".mp3"):
name = file
print(f"Renamed File: {file}\n")
os.rename(file, "song.mp3")
voice.play(discord.FFmpegPCMAudio("song.mp3"), after=lambda e:print(f'{name} has finished playing'))
voice.source = discord.PCMVolumeTransformer(voice.source)
voice.source.valume = 0.07
nname = name.rsplit("-", 2)
await ctx.send(f"Playing: {nname}")
print("Playing\n")
И это ошибка, которую он дает мне:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'play'