ytaudio: add [p]summon to join VC; revert tts join change
Add a summon command (alias ytjoin) that joins the caller's voice channel, replacing the old Audio-cog summon. _ensure_connected now moves the bot with Player.move_to when it is already in a different channel. Revert the ttstoy tts join back to the simple connect.
This commit is contained in:
+3
-12
@@ -2434,21 +2434,12 @@ class TtsToy(Cog):
|
||||
# Check if user is in a VC - we'll play there if so, but it's not required
|
||||
user_in_vc = ctx.author.voice and ctx.author.voice.channel
|
||||
|
||||
if user_in_vc:
|
||||
target_channel = ctx.author.voice.channel
|
||||
me_voice = ctx.guild.me.voice
|
||||
# Summon: connect if not in voice, or move if in a different channel.
|
||||
if me_voice is None or me_voice.channel is None:
|
||||
if user_in_vc and not ctx.guild.me.voice:
|
||||
# Connect via the shared Lavalink client (owned by the YTAudio cog).
|
||||
try:
|
||||
await lavalink.connect(target_channel)
|
||||
await lavalink.connect(ctx.author.voice.channel)
|
||||
except Exception:
|
||||
log.exception("[TTS] Failed to connect to voice channel via Lavalink.")
|
||||
elif me_voice.channel.id != target_channel.id:
|
||||
try:
|
||||
player = lavalink.get_player(ctx.guild.id)
|
||||
await player.move_to(target_channel)
|
||||
except Exception:
|
||||
log.exception("[TTS] Failed to move to the user's voice channel.")
|
||||
|
||||
mode = await self._get_tts_mode()
|
||||
|
||||
|
||||
+13
-5
@@ -323,9 +323,17 @@ class YTAudio(commands.Cog):
|
||||
if ctx.author.voice is None or ctx.author.voice.channel is None:
|
||||
await ctx.send("You need to be in a voice channel.")
|
||||
return False
|
||||
target = ctx.author.voice.channel
|
||||
me_voice = ctx.guild.me.voice
|
||||
if me_voice is None or me_voice.channel != ctx.author.voice.channel:
|
||||
await lavalink.connect(ctx.author.voice.channel)
|
||||
if me_voice is None or me_voice.channel is None:
|
||||
await lavalink.connect(target)
|
||||
elif me_voice.channel.id != target.id:
|
||||
# Already connected to a different channel: move instead of reconnecting.
|
||||
try:
|
||||
player = lavalink.get_player(ctx.guild.id)
|
||||
await player.move_to(target)
|
||||
except Exception:
|
||||
await lavalink.connect(target)
|
||||
return True
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
@@ -441,12 +449,12 @@ class YTAudio(commands.Cog):
|
||||
pass
|
||||
await ctx.send("Volume set to {}.".format(level))
|
||||
|
||||
@commands.command(name="ytjoin")
|
||||
@commands.command(name="summon", aliases=["ytjoin"])
|
||||
@commands.guild_only()
|
||||
async def join(self, ctx: commands.Context):
|
||||
"""Join your voice channel."""
|
||||
"""Summon the bot to your voice channel."""
|
||||
if await self._ensure_connected(ctx):
|
||||
await ctx.send("Joined.")
|
||||
await ctx.send("Joined your voice channel.")
|
||||
|
||||
@commands.command(name="ytleave", aliases=["ytdc"])
|
||||
@commands.guild_only()
|
||||
|
||||
Reference in New Issue
Block a user