Z
Z
Zakhar2020-10-08 16:33:46
Python
Zakhar, 2020-10-08 16:33:46

Problems with youtube_dl, what to do?

Hello, I have a problem:
Problem:

  1. Music is not always played on command (I can write a command and the bot will write to the music what it is playing, but there is no music in the voice)
  2. It can also sometimes write that there are a lot of requests (), although I did not use the play command many times (I previously wrote for this reason - they said to set a limit. I used cooldown, but after that it did not completely disappear)

Solutions I have tried:
  1. According to the first, it is fixed only when I restart the bot on the host (Heroku)
  2. According to the second, if you restart the bot on the host (Heroku), then the problem is that it says that many requests disappear for an indefinite period, and sometimes you even need to change something in the code (for example, pick up a space somewhere) to make it work

Here is part of the play command code:
@commands.command(name='play', aliases = ['p', 'pl'])
    @commands.cooldown(1, 20, commands.BucketType.member)
    async def _play(self, ctx: commands.Context, *, search: str):
        if not ctx.voice_state.voice:
            await ctx.invoke(self._join)

        async with ctx.typing():
            try:
                source = await YTDLSource.create_source(ctx, search, loop=self.bot.loop)
            except YTDLError as e:
                await ctx.send('Произошла ошибка при обработке этого запроса: {}'.format(str(e)))
            else:
                song = Song(source)

                await ctx.voice_state.songs.put(song)
                await ctx.send('Поставлен в очередь {}'.format(str(source)))

youtube_dl settings:
class YTDLSource(discord.PCMVolumeTransformer):
    YTDL_OPTIONS = {
        'format': 'bestaudio/best',
        'extractaudio': True,
        'audioformat': 'mp3',
        'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
        'restrictfilenames': True,
        'noplaylist': True,
        'nocheckcertificate': True,
        'ignoreerrors': False,
        'logtostderr': False,
        'quiet': True,
        'no_warnings': True,
        'default_search': 'auto',
        'source_address': '0.0.0.0',
    }

    FFMPEG_OPTIONS = {
        'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
        'options': '-vn',
    }

How to solve the problems that I wrote in the Problem section?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question