@Kenity

Почему бот не проигрывает музыку?

Пару дней назад бот перестал воспроизводить музыку, стоял на Heroku. У меня же, на моем пк все прекрасно работает.
Поменял хостинг, но что sprinthost, что heroku выдают ошибку : Not connected to voice.
Далее я решил обновить discord.py до новой версии.
Включил Debug, когда бот запущен с моего пк и я прописываю команду -play, в консоли видно, что бот что - то загружает, с консоли хостинга этого нет, показывает только вот это.
2022-09-19 19:12:04,914 - discord.voice_client - INFO - Connecting to voice...
2022-09-19 19:12:04,914 - discord.voice_client - INFO - Starting voice handshake... (connection attempt 1)
2022-09-19 19:12:04,914 - discord.gateway - DEBUG - Updating our voice state to {'op': 4, 'd': {'guild_id': 988761791842615297, 'channel_id': 988761792324988961, 'self_mute': False, 'self_deaf': False}}.
2022-09-19 19:12:05,073 - discord.gateway - DEBUG - For Shard ID None: WebSocket Event: {'t': 'VOICE_STATE_UPDATE', 's': 5, 'op': 0, 'd': {'member': {'user': {'username': 'Kenity', 'public_flags': 0, 'id': '993139973538729985', 'discriminator': '7247', 'bot': True, 'avatar': '00ecd768480467af1f228a66996a7b5e'}, 'roles': ['1021450860687020178'], 'premium_since': None, 'pending': False, 'nick': None, 'mute': False, 'joined_at': '2022-09-19T16:01:02.936957+00:00', 'flags': 1, 'deaf': False, 'communication_disabled_until': None, 'avatar': None}, 'user_id': '993139973538729985', 'suppress': False, 'session_id': '66b100eb7196901615f8f0baac8d4f40', 'self_video': False, 'self_mute': False, 'self_deaf': False, 'request_to_speak_timestamp': None, 'mute': False, 'guild_id': '988761791842615297', 'deaf': False, 'channel_id': '988761792324988961'}}
2022-09-19 19:12:05,073 - discord.client - DEBUG - Dispatching event socket_event_type
2022-09-19 19:12:05,073 - discord.client - DEBUG - Dispatching event voice_state_update
2022-09-19 19:12:05,217 - discord.gateway - DEBUG - For Shard ID None: WebSocket Event: {'t': 'VOICE_SERVER_UPDATE', 's': 6, 'op': 0, 'd': {'token': 'e528b1fa335f1ab8', 'guild_id': '988761791842615297', 'endpoint': 'russia2979.discord.media:443'}}
2022-09-19 19:12:05,217 - discord.client - DEBUG - Dispatching event socket_event_type
2022-09-19 19:12:05,218 - discord.voice_client - INFO - Voice handshake complete. Endpoint found russia2979.discord.media
2022-09-19 19:12:05,322 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 0, 'd': {'server_id': '988761791842615297', 'user_id': '993139973538729985', 'session_id': '66b100eb7196901615f8f0baac8d4f40', 'token': 'e528b1fa335f1ab8'}}.
2022-09-19 19:12:05,322 - discord.gateway - DEBUG - Voice websocket frame received: {'op': 8, 'd': {'v': 4, 'heartbeat_interval': 13750.0}}
2022-09-19 19:12:05,340 - discord.gateway - DEBUG - Voice websocket frame received: {'op': 2, 'd': {'streams': [{'type': 'video', 'ssrc': 44596, 'rtx_ssrc': 44597, 'rid': '', 'quality': 0, 'active': False}], 'ssrc': 44595, 'port': 50015, 'modes': ['aead_aes256_gcm_rtpsize', 'aead_aes256_gcm', 'xsalsa20_poly1305_lite_rtpsize', 'xsalsa20_poly1305_lite', 'xsalsa20_poly1305_suffix', 'xsalsa20_poly1305'], 'ip': '66.22.216.163', 'experiments': ['fixed_keyframe_interval']}}
2022-09-19 19:12:07,854 - discord.gateway - DEBUG - Keeping shard ID None websocket alive with sequence 6.
2022-09-19 19:12:08,008 - discord.gateway - DEBUG - For Shard ID None: WebSocket Event: {'t': None, 's': None, 'op': 11, 'd': None}
2022-09-19 19:12:10,324 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603930324.
2022-09-19 19:12:10,325 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603930324}.
2022-09-19 19:12:15,325 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603935325.
2022-09-19 19:12:15,326 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603935325}.
2022-09-19 19:12:20,327 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603940327.
2022-09-19 19:12:20,327 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603940327}.
2022-09-19 19:12:25,328 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603945328.
2022-09-19 19:12:25,328 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603945328}.
2022-09-19 19:12:30,329 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603950329.
2022-09-19 19:12:30,329 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603950329}.
2022-09-19 19:12:35,330 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603955330.
2022-09-19 19:12:35,330 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603955330}.
2022-09-19 19:12:40,331 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603960331.
2022-09-19 19:12:40,332 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603960331}.
2022-09-19 19:12:45,332 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603965332.
2022-09-19 19:12:45,333 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603965332}.
2022-09-19 19:12:49,105 - discord.gateway - DEBUG - Keeping shard ID None websocket alive with sequence 6.
2022-09-19 19:12:49,259 - discord.gateway - DEBUG - For Shard ID None: WebSocket Event: {'t': None, 's': None, 'op': 11, 'd': None}
2022-09-19 19:12:50,333 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603970333.
2022-09-19 19:12:50,334 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603970333}.
2022-09-19 19:12:55,334 - discord.gateway - DEBUG - Keeping shard ID None voice websocket alive with timestamp 1663603975334.
2022-09-19 19:12:55,335 - discord.gateway - DEBUG - Sending voice websocket frame: {'op': 3, 'd': 1663603975334}.

Возможно я ошибаюсь, но бот что то пытается отправить и отправляет в voice, но при этом он молчит, дискорд не показывает, даже зеленого кружочка во круг аватара.
Сам код музыки:

import asyncio
import discord
import youtube_dl
from discord.ext import commands
from discord import FFmpegPCMAudio


a = 0 


# Suppress noise about console usage from errors
youtube_dl.utils.bug_reports_message = lambda: ''


ytdl_format_options = {
    'format': 'bestaudio/best',
    'outtmpl': '%(extractor)s-%(id)s-%(title)s.%(ext)s',
    'restrictfilenames': True,
    'noplaylist': False,
    'nocheckcertificate': True,
    'ignoreerrors': False,
    'logtostderr': False,
    'quiet': True,
    'no_warnings': True,
    'default_search': 'auto',
    'source_address': '0.0.0.0' # bind to ipv4 since ipv6 addresses cause issues sometimes
}

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

ytdl = youtube_dl.YoutubeDL(ytdl_format_options)


class YTDLSource(discord.PCMVolumeTransformer):
    
    def __init__(self, source, *, data, volume=0.5):
        super().__init__(source, volume)
        self.queue = {}

        self.data = data

        self.title = data.get('title')
        self.url = data.get('url')

    @classmethod
    async def from_url(cls, url, *, loop=None, stream=False):
        loop = loop or asyncio.get_event_loop()
        data = await loop.run_in_executor(None, lambda: ytdl.extract_info(url, download=not stream))

        if 'entries' in data:
            # take first item from a playlist
            data = data['entries'][0]

        filename = data['url'] if stream else ytdl.prepare_filename(data)
        return cls(discord.FFmpegPCMAudio(filename, **ffmpeg_options), data=data)


class Music(commands.Cog):
    def __init__(self, client):
        self.client = client
        self.queue = {}
        players = "love"

    @commands.command(description="Подсоединение к каналу")
    async def join(self, ctx):
        if ctx.author.voice is None or ctx.author.voice.channel is None:
            return await ctx.send('Тебе нужно быть в голосовом канале!')

        voice_channel = ctx.author.voice.channel
        if ctx.voice_client is None:
            vc = await voice_channel.connect()
        else:
            await ctx.voice_client.move_to(voice_channel)
            vc = ctx.voice_client

    @commands.command(description="Включение музыки")
    async def play(self, ctx, *, url):
        
        if ctx.author.voice is None or ctx.author.voice.channel is None:
            return await ctx.send('Тебе нужно быть в голосовом канале!')

        voice_channel = ctx.author.voice.channel
        if ctx.voice_client is None:
            vc = await voice_channel.connect()
        else:
            await ctx.voice_client.move_to(voice_channel)
        vc = ctx.voice_client
        voice_channel = vc
        async with ctx.typing():
            player = await YTDLSource.from_url(url, loop=self.client.loop, stream=True)
            
            
                
            ctx.voice_client.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
            

                
            
            embed = discord.Embed(title="Сейчас играет ", description=f"[{player.title}]({player.url})]")
            await ctx.send(embed=embed)
            
        

    


    @commands.command()
    async def stop(self, ctx):
        await ctx.send("sTOP")
        await ctx.voice_client.stop()
        

    


    


async def setup(bot):
    await bot.add_cog(Music(bot))


Я пытался разными методами решить эту проблему, но у меня так ничего и не вышло.
  • Вопрос задан
  • 46 просмотров
Пригласить эксперта
Ваш ответ на вопрос

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

Войти через центр авторизации
Похожие вопросы