diff --git a/discord/client.py b/discord/client.py index e81e12690c5f..598a15dfe5a8 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1189,14 +1189,13 @@ async def fetch_channel(self, channel_id): factory, ch_type = _channel_factory(data['type']) if factory is None: - raise TypeError('Unknown channel type %s.' % data['type']) + raise InvalidData('Unknown channel type {type} for channel ID {id}.'.format_map(data)) if ch_type in (ChannelType.group, ChannelType.private): channel = factory(me=self.user, data=data, state=self._connection) else: guild_id = int(data['guild_id']) guild = self.get_guild(guild_id) or Object(id=guild_id) - channel = factory(guild=guild, state=self._connection, data=data) return channel diff --git a/discord/errors.py b/discord/errors.py index 6669e1680b9a..10aa28465c76 100644 --- a/discord/errors.py +++ b/discord/errors.py @@ -125,6 +125,12 @@ class NotFound(HTTPException): pass +class InvalidData(ClientException): + """Exception that's raised when the library encounters unknown + or invalid data from Discord. + """ + pass + class InvalidArgument(ClientException): """Exception that's thrown when an argument to a function is invalid some way (e.g. wrong value or wrong type). diff --git a/discord/guild.py b/discord/guild.py index e067175e847e..66d7b3a74f4c 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -32,6 +32,7 @@ from .member import Member, VoiceState from .activity import create_activity from .emoji import Emoji +from .errors import InvalidData from .permissions import PermissionOverwrite from .colour import Colour from .errors import InvalidArgument, ClientException @@ -955,7 +956,7 @@ async def fetch_channels(self): def convert(d): factory, ch_type = _channel_factory(d['type']) if factory is None: - raise TypeError('Unknown channel type %s.' % d['type']) + raise InvalidData('Unknown channel type {type} for channel ID {id}.'.format_map(data)) channel = factory(guild=self, state=self._state, data=d) return channel