async def next_track_callback(self, interaction: disnake.Interaction):
await interaction.response.defer()
print("NEXT AUDIO BUTTON CLICKED!")
await self.play_next()
async def play_next(self):
self.voice_client.stop()
if self.music_queue.__len__() > 0:
print("retrieving next audio")
track_name, url = self.music_queue[0]['title'], self.music_queue[0]['url']
if self.embed.fields.__len__() == 0:
self.embed.add_field(name="Playing now", value=track_name, inline=True)
else:
self.embed.set_field_at(index=0, name="Playing now", value=track_name, inline=True)
self.music_queue.pop(0)
print("after got link from queue= " + str(len(self.music_queue)))
#try:
self.que_fetch()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'}
source = disnake.PCMVolumeTransformer(
disnake.FFmpegPCMAudio(source=url, **FFMPEG_OPTIONS,
executable=r"dependencies\FFMPEG\bin\ffmpeg.exe"))
def play_next_callback(e):
coro = self.play_next()
future = asyncio.run_coroutine_threadsafe(coro, self.bot.loop)
future.result()
self.voice_client.play(source=source, after=play_next_callback)
self.is_playing = True
#except disnake.ClientException as e:
#print("player playing!: ", e)
#except Exception as e:
#print(e)
else:
print("stopping!")
self.embed.clear_fields()
coro = self.stopall()
asyncio.run_coroutine_threadsafe(coro=coro, loop=self.bot.loop).result()
return
<br>
retrieving next audio<br>
after got link from queue= 2<br>
correcting embed<br>
correcting embed<br>
NEXT AUDIO BUTTON CLICKED!<br>
retrieving next audio<br>
after got link from queue= 2<br>
correcting embed<br>
retrieving next audio<br>
after got link from queue= 1<br>
correcting embed<br>
retrieving next audio<br>
after got link from queue= 0<br>
correcting embed<br>
stopping!<br>
<br>
async def next_track_callback(self, interaction: disnake.Interaction):
await interaction.response.defer()
print("NEXT AUDIO BUTTON CLICKED!")
await self.play_next()
async def play_next(self):
self.voice_client.stop()
if self.music_queue.__len__() > 0:
print("retrieving next audio")
track_name, url = self.music_queue[0]['title'], self.music_queue[0]['url']
if self.embed.fields.__len__() == 0:
self.embed.add_field(name="Playing now", value=track_name, inline=True)
else:
self.embed.set_field_at(index=0, name="Playing now", value=track_name, inline=True)
self.music_queue.pop(0)
print("after got link from queue= " + str(len(self.music_queue)))
#try:
self.que_fetch()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'}
source = disnake.PCMVolumeTransformer(
disnake.FFmpegPCMAudio(source=url, **FFMPEG_OPTIONS,
executable=r"dependencies\FFMPEG\bin\ffmpeg.exe"))
def play_next_callback(e):
coro = self.play_next()
future = asyncio.run_coroutine_threadsafe(coro, self.bot.loop)
future.result()
self.voice_client.play(source=source, after=play_next_callback)
self.is_playing = True
#except disnake.ClientException as e:
#print("player playing!: ", e)
#except Exception as e:
#print(e)
else:
print("stopping!")
self.embed.clear_fields()
coro = self.stopall()
asyncio.run_coroutine_threadsafe(coro=coro, loop=self.bot.loop).result()
return
<br>
retrieving next audio<br>
after got link from queue= 2<br>
correcting embed<br>
correcting embed<br>
NEXT AUDIO BUTTON CLICKED!<br>
retrieving next audio<br>
after got link from queue= 2<br>
correcting embed<br>
retrieving next audio<br>
after got link from queue= 1<br>
correcting embed<br>
retrieving next audio<br>
after got link from queue= 0<br>
correcting embed<br>
stopping!<br>
<br>
def play_next(self):
self.voice_client.pause()
self.voice_client.stop() #здесь возможно ошибка
if self.music_queue.__len__() > 0:
print("next comp")
track_name, url = self.music_queue[0]['title'], self.music_queue[0]['url']
if self.embed.fields.__len__() == 0:
self.embed.add_field(name="Playing now", value=track_name, inline=True)
else:
self.embed.set_field_at(index=0, name="Playing now", value=track_name, inline=True)
print("before = " + str(len(self.music_queue)))
self.music_queue.pop(0)
print("after = " + str(len(self.music_queue)))
try:
#after next_track_callback was called, and play_next called, track switches twice
self.que_fetch()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
source = disnake.PCMVolumeTransformer(disnake.FFmpegPCMAudio(source=url, **FFMPEG_OPTIONS,executable=r"dependencies\FFMPEG\bin\ffmpeg.exe"))
self.voice_client.play(source= source, after=lambda e: self.play_next()) # и тут возможно тоже
self.is_playing = True
except disnake.ClientException as e:
print("player playing!: ", e)
except Exception as e:
print(e)
else:
print("stopping!")
self.embed.clear_fields()
coro = self.stopall()
asyncio.run_coroutine_threadsafe(coro=coro, loop=self.bot.loop).result()
return
async def next_track_callback(self, interaction: disnake.Interaction):
await interaction.response.defer()
self.play_next()
next comp
before = 3
after = 2
correcting q
# здесь была нажата кнопка переключения трека
next comp
before = 2
after = 1
correcting q
next comp
before = 1
after = 0
correcting q
stopping!
stopping!
at stop: 404 Not Found (error code: 10008): Unknown Message
Traceback (most recent call last):
File "C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\player.py", line 747, in _call_after
self.after(error)
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 80, in <lambda>
self.voice_client.play(source, after=lambda e: self.my_after(e))
^^^^^^^^^^^^^^^^
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 49, in my_after
asyncio.run_coroutine_threadsafe(coro, loop= asyncio.get_event_loop()).result()
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\events.py", line 677, in get_event_loop
raise RuntimeError('There is no current event loop in thread %r.'
RuntimeError: There is no current event loop in thread 'Thread-3'.
C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\player.py:751: RuntimeWarning: coroutine 'VoicePart.play_next' was never awaited
traceback.print_exception(type(exc), exc, exc.__traceback__)
Object allocated at (most recent call last):
File "D:\WORKDIR\BOT\cogs\VoicePart.py", lineno 48
coro = self.play_next()
def my_after(self, error):
if error is not None:
print(error)
coro = self.play_next()
asyncio.run_coroutine_threadsafe(coro, asyncio.get_event_loop).result()
async def play_next(self):
if len(self.music_queue) > 0:
self.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'}
self.is_playing = True
track_name, url = self.music_queue[0]['title'], self.music_queue[0]['url']
if self.embed.fields.__len__() == 0:
self.embed.add_field(name="Playing now", value=track_name, inline=True)
else:
self.embed.set_field_at(index=0, name="Playing now", value=track_name, inline=True)
self.music_queue.pop(0)
if self.music_queue.__len__() > 0:
self.que_fetch()
else:
self.embed.remove_field(1)
self.next_track.disabled = True
try:
await asyncio.sleep(2)
self.voice_client.stop()
source = disnake.FFmpegPCMAudio(source=url, **FFMPEG_OPTIONS,
executable=r"dependencies\FFMPEG\bin\ffmpeg.exe")
self.voice_client.play(source, after=lambda e:self.my_after(e))
except disnake.ClientException as e:
print(e)
except Exception as e:
print(e)
await self.message.edit(view=self.view, embed=self.embed)
else:
self.embed.clear_fields()
await self.stopall()
return
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 48, in my_after
asyncio.run_coroutine_threadsafe(coro, asyncio.get_event_loop).result()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\tasks.py", line 926, in run_coroutine_threadsafe
loop.call_soon_threadsafe(callback)
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'builtin_function_or_method' object has no attribute 'call_soon_threadsafe'
def play_next(self):
if len(self.music_queue) > 0:
self.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5',
'options': '-vn'}
self.is_playing = True
track_name, url = self.music_queue[0]['title'], self.music_queue[0]['url']
if self.embed.fields.__len__() == 0:
self.embed.add_field(name="Playing now", value=track_name, inline=True)
else:
self.embed.set_field_at(index=0, name="Playing now", value=track_name, inline=True)
self.music_queue.pop(0)
if self.music_queue.__len__() > 0:
self.que_fetch()
else:
self.embed.remove_field(1)
self.next_track.disabled = True
try:
self.voice_client.play(disnake.FFmpegPCMAudio(source=url, **FFMPEG_OPTIONS,
executable=r"dependencies\FFMPEG\bin\ffmpeg.exe"),
after=lambda e: print('Player error: %s' % e) if e else self.play_next())
except disnake.ClientException as e:
print("already playing aud")
except Exception as e:
print(e)
else:
self.issent_control_message = False
self.voice_client.stop()
self.is_playing = False
fut1 = asyncio.run_coroutine_threadsafe(self.message.delete(), disnake.ext.tasks.loop)
fut2 = asyncio.run_coroutine_threadsafe(self.voice_client.disconnect(), disnake.ext.tasks.loop)
try:
fut1.result()
fut2.result()
except:
pass
return
<br>
Traceback (most recent call last):<br>
File "C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\player.py", line 747, in _call_after<br>
self.after(error)<br>
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 72, in <br>
after=lambda e: print('Player error: %s' % e) if e else self.play_next())<br>
^^^^^^^^^^^^^^^^<br>
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 81, in play_next<br>
fut1 = asyncio.run_coroutine_threadsafe(self.message.delete(), disnake.ext.tasks.loop)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\tasks.py", line 926, in run_coroutine_threadsafe<br>
loop.call_soon_threadsafe(callback)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^<br>
AttributeError: 'function' object has no attribute 'call_soon_threadsafe'<br>
C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\player.py:751: RuntimeWarning: coroutine 'Message.delete' was never awaited<br>
traceback.print_exception(type(exc), exc, exc.__traceback__)<br>
RuntimeWarning: Enable tracemalloc to get the object allocation traceback<br>
<br>
import tracemalloc<br>
tracemalloc.start()<br>
<br>
<br>
Traceback (most recent call last):<br>
File "C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\ext\commands\bot_base.py", line 589, in invoke<br>
await ctx.command.invoke(ctx)<br>
File "C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\ext\commands\core.py", line 914, in invoke<br>
await injected(*ctx.args, **ctx.kwargs)<br>
File "C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\ext\commands\core.py", line 182, in wrapped<br>
raise CommandInvokeError(exc) from exc<br>
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'NoneType' object has no attribute 'edit'<br>
Traceback (most recent call last):<br>
File "C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\player.py", line 747, in _call_after<br>
self.after(error)<br>
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 73, in <br>
after=lambda e: print('Player error: %s' % e) if e else self.play_next())<br>
^^^^^^^^^^^^^^^^<br>
File "D:\WORKDIR\BOT\cogs\VoicePart.py", line 82, in play_next<br>
fut1 = asyncio.run_coroutine_threadsafe(self.message.delete(), disnake.ext.tasks.loop)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br>
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.11_3.11.1008.0_x64__qbz5n2kfra8p0\Lib\asyncio\tasks.py", line 926, in run_coroutine_threadsafe<br>
loop.call_soon_threadsafe(callback)<br>
^^^^^^^^^^^^^^^^^^^^^^^^^<br>
AttributeError: 'function' object has no attribute 'call_soon_threadsafe'<br>
C:\Users\nikit\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\disnake\player.py:751: RuntimeWarning: coroutine 'Message.delete' was never awaited<br>
traceback.print_exception(type(exc), exc, exc.__traceback__)<br>
Object allocated at (most recent call last):<br>
File "D:\WORKDIR\BOT\cogs\VoicePart.py", lineno 82<br>
fut1 = asyncio.run_coroutine_threadsafe(self.message.delete(), disnake.ext.tasks.loop)<br>
<br>
Этот вопрос задан не как поиск решения, но как помощь в понимании, проблемы почему не работает
Мой кусок решения расписан подробно, чтобы смотрящий человек понимал, что тут происходит, и что ничего не упущено при передаче аргументов в функцию удаления