Added auto-disconnect feature
This commit is contained in:
19
Music-Bot.py
19
Music-Bot.py
@@ -188,7 +188,8 @@ else:
|
||||
try:
|
||||
player = await YTDLSource.from_url(url, loop=bot.loop)
|
||||
ctx.voice_client.play(
|
||||
player, after=await ctx.voice_client.disconnect())
|
||||
player, after=lambda e: print(f"Player error: {e}") if e else None
|
||||
)
|
||||
except discord.HTTPException as err:
|
||||
raise commands.CommandError(err)
|
||||
finally:
|
||||
@@ -200,7 +201,8 @@ else:
|
||||
async with ctx.typing():
|
||||
player = await YTDLSource.from_url(url, loop=bot.loop, stream=True)
|
||||
ctx.voice_client.play(
|
||||
player, after=await ctx.voice_client.disconnect())
|
||||
player, after=lambda e: print(f"Player error: {e}") if e else None
|
||||
)
|
||||
|
||||
await ctx.respond(f"{success}Now playing: `{player.title}`\nRequested by {ctx.author.mention}")
|
||||
|
||||
@@ -239,7 +241,8 @@ else:
|
||||
try:
|
||||
player = await YTDLSource.from_url(url, loop=bot.loop)
|
||||
ctx.voice_client.play(
|
||||
player, after=await ctx.voice_client.disconnect())
|
||||
player, after=lambda e: print(f"Player error: {e}") if e else None
|
||||
)
|
||||
except discord.HTTPException as err:
|
||||
raise commands.CommandError(err)
|
||||
finally:
|
||||
@@ -258,6 +261,16 @@ else:
|
||||
elif ctx.voice_client.is_playing():
|
||||
ctx.voice_client.stop()
|
||||
|
||||
@bot.event()
|
||||
async def on_voice_state_update(ctx: commands.Context):
|
||||
while True:
|
||||
await asyncio.sleep(1)
|
||||
if ctx.voice_client.is_playing() and not ctx.voice_client.is_paused():
|
||||
pass
|
||||
else:
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
|
||||
|
||||
|
||||
@bot.event
|
||||
|
||||
Reference in New Issue
Block a user