aboutsummaryrefslogtreecommitdiff
path: root/discord/member.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2015-11-20 17:39:19 -0500
committerRapptz <[email protected]>2015-11-20 17:39:51 -0500
commit5ca04ea08f3d64d4e2bfb1b86c7a8a01b2480f87 (patch)
tree80501a19e4320067c808ab8d5c3a6ccc824461f8 /discord/member.py
parentAllow sending raw file objects in memory with client.send_raw_file (diff)
downloaddiscord.py-5ca04ea08f3d64d4e2bfb1b86c7a8a01b2480f87.tar.xz
discord.py-5ca04ea08f3d64d4e2bfb1b86c7a8a01b2480f87.zip
Use try-except instead of checking for membership.
Basically, a lot of the checks revolving "if x in y" could be written more efficiently by doing the task anyway and ignoring the exception a la the EAFP guideline.
Diffstat (limited to 'discord/member.py')
-rw-r--r--discord/member.py17
1 files changed, 10 insertions, 7 deletions
diff --git a/discord/member.py b/discord/member.py
index 794f6729..b8597e8e 100644
--- a/discord/member.py
+++ b/discord/member.py
@@ -95,11 +95,14 @@ class Member(User):
if old_channel is None and self.voice_channel is not None:
# we joined a channel
self.voice_channel.voice_members.append(self)
- elif old_channel is not None and self.voice_channel is None:
- if self in old_channel.voice_members:
- # we left a channel
+ elif old_channel is not None:
+ try:
+ # we either left a channel or we switched channels
old_channel.voice_members.remove(self)
- elif old_channel is not None and self.voice_channel is not None:
- if self in old_channel.voice_members:
- old_channel.voice_members.remove(self)
- self.voice_channel.voice_members.append(self)
+ except ValueError:
+ pass
+ finally:
+ # we switched channels
+ if self.voice_channel is not None:
+ self.voice_channel.voice_members.append(self)
+