Задать вопрос
@Trias28

Есть музыкальный бот для discord, во время проигрывания музыкаи выдает ошибку, кто нибудь может помочь исправить?

import requests
import discord
from discord.utils import get
from youtube_dl import YoutubeDL
from discord.ext import commands
from queue import Queue
import asyncio


class Song(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.playList = Queue()
        self.song_stop = False
        self.voices = None
        self.now_song = ' '
        self.loop = False


    @commands.command(pass_context=True)
    async def leave(self, ctx):
        self.voices = get(self.bot.voice_clients, guild=ctx.guild)

        if self.voices and self.voices.is_connected():
            await self.voices.disconnect()

    async def join(self, ctx, voice):
        channel = ctx.author.voice.channel

        if voice and voice.is_connected():
            await voice.move_to(channel)
        else:
            voice = await channel.connect()

    def search(self, arg):
        with YoutubeDL(
                {'format': 'bestaudio', 'noplaylist': 'True', 'ffmpeg_location': 'C:\\ffmpeg\\bin\\ffmpeg.exe'}) as ydl:
            try:
                requests.get(arg)
            except:
                info = ydl.extract_info(f"ytsearch:{arg}", download=False)['entries'][0]
            else:
                info = ydl.extract_info(arg, download=False)
        return (info, info['formats'][0]['url'])

    async def play_next(self, ctx):
        FFMPEG_OPTS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
        if not self.playList.empty() and not self.now_song == ' ':
            if self.loop:
                self.playList.put(self.now_song)
        if not self.playList.empty():
            video, source = self.search(self.playList.get())
            self.now_song = video['title']
            await ctx.send(f'Щас играет  {self.now_song} ')

            self.voices.play(discord.FFmpegPCMAudio(source, options=FFMPEG_OPTS), after=lambda e: asyncio.run(self.play_next(ctx)))

    @commands.command(pass_context=True)
    async def play(self, ctx, *, query):
        self.playList.put(query)
        self.voices = get(self.bot.voice_clients, guild=ctx.guild)
        channel = ctx.author.voice.channel
        if self.voices and self.voices.is_connected:
            await self.voices.move_to(channel)
        else:
            self.voices = await channel.connect()
        if not self.voices.is_playing():
            await self.play_next(ctx)
        else:
            await ctx.send(f'Песня добавлена в очередь.')

    @commands.command(pass_context=True)
    async def pause(self, ctx):
        if self.voices.is_playing():
            self.voices.pause()
            self.song_stop = True
        else:
            await ctx.send(f'Ща ниче не играет чет...')

    @commands.command(pass_context=True)
    async def resume(self, ctx):
        if self.song_stop:
            self.voices.resume()
        else:
            await ctx.send(f'Нечего останавливать щас')

    @commands.command(pass_context=True)
    async def skip(self, ctx):
        if not self.song_stop and self.voices.is_playing():
            self.voices.pause()
            await self.play_next(ctx)
        else:
            await ctx.send(f'Нечего пропускать')

    @commands.command(pass_context=True)
    async def loop(self, ctx):
        if not self.song_stop and self.voices.is_playing():
            self.loop = True
            await ctx.send(f'Очередь в цикле ХРЮ-Ю-Ю')
        else:
            await ctx.send(f'Нет песен в очереди ')

    @commands.command(pass_context=True)
    async def del_loop(self, ctx):
        if not self.song_stop and self.voices.is_playing():
            self.loop = False
        else:
            await ctx.send(f'Нет зацикливания ')

    @commands.command(pass_context=True)
    async def clear_playlist(self, ctx):
        while not self.playList.empty():
            self.playList.get()


def setup(bot):
    bot.add_cog(Song(bot))


[tls @ 0000000000e13380] Unable to read from socket
    Last message repeated 2 times
https://rr13---sn-n8v7kn7k.googlevideo.com/videoplayback?expire=1640301994&ei=SrHEYeniGdmjyQXmvoLoDw&ip=188.187.15.229&id=o-APChxz7morf9u9qNqr_UYB3WfMDdNNT-LWxiWew36PEn&itag=249&source=youtube&requiressl=yes&mh=5f&mm=31%2C29&mn=sn-n8v7kn7k%2Csn-n8v7zns6&ms=au%2Crdu&mv=m&mvi=13&pl=22&initcwndbps=1717500&vprv=1&mime=audio%2Fwebm&ns=86JeEvCjuvwI22q83MGWvQUG&gir=yes&clen=862289&dur=129.141&lmt=1613834503774958&mt=1640280068&fvip=13&keepalive=yes&fexp=24001373%2C24007246&c=WEB&txp=5431432&n=qE6m_vXy2WeSbnQh&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRAIgJ51NBjiT9G8W_xz_mZGmHZmIhksHN-2LTFUhou7s_L0CICliKqGFO6Q7IqXYjQiazb3RHjTOZolzoPjHpj8ZOzsy&sig=AOq0QJ8wRQIgL3wTqTBIToTb5WeMK6nU5KLowphjv2qFQiHzgqgziKQCIQCkGvZqpcTFYxuuHmuCt9s6glf4VX_3OkfxolrEOCwoSw==: Unknown error
[tls @ 0000000000e13380] Failed to send close message
  • Вопрос задан
  • 76 просмотров
Подписаться 1 Простой 2 комментария
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы