I'm working on a discord bot and trying to solve this. I want to know how could I use await in non async function or if I can await a function in the lambda line the last line in the code.
I have tried doing asyncio.run
with the player variable and I have tried asyncio.run_coroutine_threadsafe
too and it didnt work.
Any ideas on how to make it work?
Code:
def queue_check(self, ctx):
global queue_list
global loop
global playing
if loop is True:
queue_list.append(playing)
elif loop is False:
playing = ''
if ctx.channel.last_message.content == '$skip' or '$s':
return
song = queue_list.pop(0)
player = await YTDLSource.from_url(song, loop=self.client.loop, stream=True)
ctx.voice_client.play(player, after= queue_check(self,ctx))
@commands.command(aliases=['p'])
@commands.guild_only()
async def play(self, ctx, *, url):
global queue_list
global playing
if ctx.voice_client is None:
if ctx.author.voice:
await ctx.author.voice.channel.connect()
else:
return await ctx.send("> You are not connected to a voice channel.")
async with ctx.typing():
player = await YTDLSource.from_url(url, loop=self.client.loop, stream=True)
await ctx.send(f'> :musical_note: Now playing: **{player.title}** ')
playing = url
await ctx.voice_client.play(player, after=lambda e: queue_check(self,ctx))
await
must be defined asasync
– Higley