<p>你可以这么做</p>
<pre><code>async def play_next(self, ctx):
voicechannel = discord.utils.get(self.bot.voice_clients, guild=ctx.guild)
if len(self.song_queue) >= 1:
del self.song_queue[0]
source = os.path.join(self.QUEUE_PATH, self.song_queue[0])
audio = MP3(source)
await self.postEmbed(ctx, self.song_queue[0], audio.info.length)
await self.voicechannel.play(discord.FFmpegPCMAudio(source=source), after=lambda e: self.play_next(ctx))
else:
await self.voicechannel.disconnect()
</code></pre>
<p>注意:异步可以包含在任何def中。
或者你可以这样做</p>
<pre><code>@commands.command() #If its on cog, if its not on cog change it to @client.command or @bot.command()
async def play_next(self, ctx):
voicechannel = discord.utils.get(self.bot.voice_clients, guild=ctx.guild)
if len(self.song_queue) >= 1:
del self.song_queue[0]
source = os.path.join(self.QUEUE_PATH, self.song_queue[0])
audio = MP3(source)
await self.postEmbed(ctx, self.song_queue[0], audio.info.length)
await self.voicechannel.play(discord.FFmpegPCMAudio(source=source), after=lambda e: self.play_next(ctx))
else:
await self.voicechannel.disconnect()
</code></pre>
<p>或者删除<code>@commands.command()</code>并发出另一个类似这样的命令</p>
<pre><code>@commands.command()
async def play(self, ctx, *, url):
await play_next(url)
"""Say something or add another code"""
</code></pre>