ttstoy: add universal [p]disconnect command to leave VC
This commit is contained in:
@@ -3061,6 +3061,39 @@ class TtsToy(Cog):
|
|||||||
except Exception:
|
except Exception:
|
||||||
log.exception("[Accessibility] voice reset error")
|
log.exception("[Accessibility] voice reset error")
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
# DISCONNECT FROM VOICE (universal)
|
||||||
|
# ---------------------------------------------------------------------
|
||||||
|
@commands.command(name="disconnect", aliases=["dc", "leave"])
|
||||||
|
@commands.guild_only()
|
||||||
|
async def disconnect_vc(self, ctx: commands.Context):
|
||||||
|
"""Disconnect the bot from voice chat."""
|
||||||
|
if not ctx.guild.me.voice:
|
||||||
|
return await ctx.send("Not in a voice channel.")
|
||||||
|
|
||||||
|
# Try lavalink player first (cleans up its queue/state).
|
||||||
|
try:
|
||||||
|
player = lavalink.get_player(ctx.guild.id)
|
||||||
|
player.queue.clear()
|
||||||
|
await player.stop()
|
||||||
|
await player.disconnect()
|
||||||
|
await ctx.send("Disconnected.")
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
# Fallback: native discord.py voice client.
|
||||||
|
vc = ctx.guild.voice_client
|
||||||
|
if vc:
|
||||||
|
try:
|
||||||
|
await vc.disconnect(force=True)
|
||||||
|
await ctx.send("Disconnected.")
|
||||||
|
return
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
await ctx.send("Disconnected.")
|
||||||
|
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
# SPEAK COMMAND (JUST [p]tts)
|
# SPEAK COMMAND (JUST [p]tts)
|
||||||
# ---------------------------------------------------------------------
|
# ---------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user