diff --git a/discord/voice_client.py b/discord/voice_client.py index f24441301..da8eff3bf 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -211,16 +211,16 @@ class VoiceClient: self.socket.sendto(packet, (self.endpoint_ip, self.voice_port)) recv = yield from self.loop.sock_recv(self.socket, 70) log.debug('received packet in initial_connection: {}'.format(recv)) - ip = [] - for x in range(4, len(recv)): - val = recv[x] - if val == 0: - break - ip.append(chr(val)) + # the ip is ascii starting at the 4th byte and ending at the first null + ip_start = 4 + ip_end = recv.index(0, ip_start) + self.ip = recv[ip_start:ip_end].decode('ascii') + + # the port is a little endian unsigned short in the last two bytes + # yes, this is different endianness from everything else + self.port = struct.unpack_from('