I tried making a Discord bot with discord.py
. I'm at the skip command section. I have finished the other parts like play and queue commands.
I tried using the command self.vc.stop()
to stop the song and skip to the next one but it didn't work, can anyone help me? Here is the detailed skip command I did:
class music_cog(commands.Cog):
# all the stuff over here
@commands.command(aliases=["continue"])
async def skip(self, ctx):
if self.vc != "":
self.vc.stop()
# plays the next song
await self.play_music()
I'm not familiar with what you are trying to do but it looks like MrSpaar's answer might help you.
Depending on how you implemented play_music()
, you should use the after
argument of vc.play()
. Here is the snippet that was provided:
import asyncio
def play_next(ctx, source):
if len(self.song_queue) >= 1:
del self.song_queue[0]
vc = get(self.bot.voice_clients, guild=ctx.guild)
vc.play(discord.FFmpegPCMAudio(source=source, after=lambda e: play_next(ctx))
asyncio.run_coroutine_threadsafe(ctx.send("No more songs in queue."))
The key here is to use skip()
as a lambda for after
from what I understood.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.