diff --git a/src/tuimble/client.py b/src/tuimble/client.py index 056cf7c..aab854a 100644 --- a/src/tuimble/client.py +++ b/src/tuimble/client.py @@ -229,7 +229,12 @@ class MumbleClient: def send_text(self, message: str): """Send a text message to the current channel.""" if self._mumble and self._connected: - ch = self._mumble.channels[self._mumble.users.myself["channel_id"]] + try: + cid = self._mumble.users.myself["channel_id"] + ch = self._mumble.channels[cid] + except (KeyError, AttributeError): + log.warning("send_text: channel unavailable") + return ch.send_text_message(message) def send_audio(self, pcm_data: bytes): @@ -238,9 +243,16 @@ class MumbleClient: self._mumble.sound_output.add_sound(pcm_data) def join_channel(self, channel_id: int): - """Move to a different channel.""" + """Move to a different channel. + + Raises: + ValueError: If the channel no longer exists on the server. + """ if self._mumble and self._connected: - self._mumble.channels[channel_id].move_in() + ch = self._mumble.channels.get(channel_id) + if ch is None: + raise ValueError(f"channel {channel_id} not found") + ch.move_in() def set_self_deaf(self, deaf: bool): """Toggle self-deafen on the server."""