Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
fix: handle references to a voice channel that doesnt exist (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
LordOfPolls committed Oct 14, 2022
1 parent aa45a06 commit b6760f8
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions naff/models/discord/voice_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,22 @@ def channel(self) -> "TYPE_VOICE_CHANNEL":
"""The channel the user is connected to."""
channel: "TYPE_VOICE_CHANNEL" = self._client.cache.get_channel(self._channel_id)

# make sure the member is showing up as a part of the channel
# this is relevant for VoiceStateUpdate.before
# noinspection PyProtectedMember
if self._member_id not in channel._voice_member_ids:
# the list of voice members need to be deepcopied, otherwise the cached obj will be updated
if channel:
# make sure the member is showing up as a part of the channel
# this is relevant for VoiceStateUpdate.before
# noinspection PyProtectedMember
voice_member_ids = copy.deepcopy(channel._voice_member_ids)

# create a copy of the obj
channel = copy.copy(channel)
channel._voice_member_ids = voice_member_ids

# add the member to that list
# noinspection PyProtectedMember
channel._voice_member_ids.append(self._member_id)
if self._member_id not in channel._voice_member_ids:
# the list of voice members need to be deepcopied, otherwise the cached obj will be updated
# noinspection PyProtectedMember
voice_member_ids = copy.deepcopy(channel._voice_member_ids)

# create a copy of the obj
channel = copy.copy(channel)
channel._voice_member_ids = voice_member_ids

# add the member to that list
# noinspection PyProtectedMember
channel._voice_member_ids.append(self._member_id)

return channel

Expand Down

0 comments on commit b6760f8

Please sign in to comment.