ttstoy: make tts join behave as a summon
Connect to the caller's voice channel when the bot is not in voice, and move to the caller's channel if the bot is currently in a different one (via Player.move_to). Previously it only connected when the bot had no voice state, so it would not follow the user between channels.
This commit is contained in:
+15
-6
@@ -2434,12 +2434,21 @@ class TtsToy(Cog):
|
|||||||
# Check if user is in a VC - we'll play there if so, but it's not required
|
# 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
|
user_in_vc = ctx.author.voice and ctx.author.voice.channel
|
||||||
|
|
||||||
if user_in_vc and not ctx.guild.me.voice:
|
if user_in_vc:
|
||||||
# Connect via the shared Lavalink client (owned by the YTAudio cog).
|
target_channel = ctx.author.voice.channel
|
||||||
try:
|
me_voice = ctx.guild.me.voice
|
||||||
await lavalink.connect(ctx.author.voice.channel)
|
# Summon: connect if not in voice, or move if in a different channel.
|
||||||
except Exception:
|
if me_voice is None or me_voice.channel is None:
|
||||||
log.exception("[TTS] Failed to connect to voice channel via Lavalink.")
|
try:
|
||||||
|
await lavalink.connect(target_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()
|
mode = await self._get_tts_mode()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user