Wolf_Yout
@Wolf_Yout

RuntimeError: no running event loop, что делать?

Код, где происходит эта ошибка:
async def my_after(ctx):
            #os.remove(f"songs/{ctx.guild.id}.mp3")
            voice_state = ctx.guild.voice_client
            names = []
            requesters = []
            artists = []
            ids = []
            albumids = []
            positions = []
            guilds = []
            lyrics = []
            with sqlite3.connect("database.db") as db:
                c = db.cursor()
                for n, r, a, i, ai, ly, g, im, p in c.execute("SELECT * FROM songs WHERE guild = ?", (ctx.guild.id,)):
                    positions.append(p)
                    names.append(n)
                    requesters.append(r)
                    artists.append(a)
                    guilds.append(g)
                    ids.append(i)
                    albumids.append(ai)
                    if n and not ly:
                        lyrics.append(None)
                    else:
                        lyrics.append(ly)
                c.execute("DELETE FROM songs WHERE guild = ? AND position = ?", (guilds[0], positions[0],))
            if voice_state and voice_state.is_connected():
                try:
                    positions[1]
                except:
                    pass
                else:
                    #Song.download_track(ctx, {"id": ids[1], "title": names[1], "artist": artists[1], "albumid": albumids[1], "lyrics": lyrics[1]})
                    await Song.play(ctx)

    def init_after(ctx):
        # loop = asyncio.new_event_loop()
        # asyncio.set_event_loop(loop)
        # task = asyncio.create_task(Song.my_after(ctx))
        # loop.run_until_complete(task)
        asyncio.create_task(Song.my_after(ctx))

    async def play(ctx):
        voice_state = ctx.guild.voice_client
        if not voice_state:
            error = await Song.join_channel(ctx)
            if error:
                return error
        voice_state = ctx.guild.voice_client
        if voice_state.is_playing():
            return "alreadyPlay"
        ids = []
        names = []
        requesters = []
        alis = []
        authors = []
        positions = []
        imgs = []
        with sqlite3.connect("database.db") as db:
            c = db.cursor()
            for n, r, a, i, ai, ly, g, im, p in c.execute("SELECT * FROM songs WHERE guild = ?", (ctx.guild.id,)):
                ids.append(i)
                names.append(n)
                requesters.append(r)
                alis.append(ai)
                authors.append(a)
                positions.append(p)
                imgs.append(imgs)
        if not os.path.isfile(f"songs/{ids[0]}.mp3"):
            Song.download_track(ctx, {'id': ids[0]})
        voice_state.play(disnake.FFmpegPCMAudio(f"songs/{ids[0]}.mp3"), after=lambda e: Song.init_after(ctx))
        voice_state.is_playing()
        embed = disnake.Embed(title=names[0],color=0x228b22)
        embed.add_field(name=lang(ctx,"Главный автор:"),value=authors[0])
        embed.add_field(name=lang(ctx,"Предложил:"),value=f"<@{requesters[0]}>")
        embed.add_field(name=lang(ctx,"Источник:"),value="<:yandexMusic:1056924402790436934> Yandex Music\n")
        embed.add_field(name=lang(ctx,"Ссылка:"),value=f"[**{lang(ctx,'Это кликабельная ссылка!')}**](https://music.yandex.ru/album/{alis[0]}/track/{ids[0]})")
        embed.add_field(name=lang(ctx,"Позиция:"),value=positions[0])
        embed.set_thumbnail(url = imgs[0])
        await ctx.channel.send(embed=embed)
        return None

текст ошибки:
Traceback (most recent call last):
  File "/home/container/.local/lib/python3.9/site-packages/disnake/player.py", line 742, in _call_after
    self.after(error)
  File "/home/container/main.py", line 196, in <lambda>
    voice_state.play(disnake.FFmpegPCMAudio(f"songs/{ids[0]}.mp3"), after=lambda e: Song.init_after(ctx))
  File "/home/container/main.py", line 168, in init_after
    asyncio.create_task(Song.my_after(ctx))
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 360, in create_task
    loop = events.get_running_loop()
RuntimeError: no running event loop
/home/container/.local/lib/python3.9/site-packages/disnake/player.py:746: RuntimeWarning: coroutine 'Song.my_after' was never awaited
  traceback.print_exception(type(exc), exc, exc.__traceback__)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

Как исправить данную ошибку?
  • Вопрос задан
  • 1161 просмотр
Пригласить эксперта
Ответы на вопрос 1
phaggi
@phaggi Куратор тега Python
лужу, паяю, ЭВМы починяю
Попробуйте поменять asyncio.create_task(Song.my_after(ctx)) на await asyncio.create_task(Song.my_after(ctx))
Ответ написан
Ваш ответ на вопрос

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

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