fix: check channel type before the guild-derivation guard (dpylogger-9)

The wrong-type channel check sat after the no-resolvable-guild guard, so a
non-TextChannel object passed without a guild raised the misleading "channel
provided without a resolvable guild" instead of "is not a text channel" - the
accurate message only fired when a guild was also supplied. Move the type
check first so both branches report the real problem.

Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
2026-07-06 00:11:05 -04:00
parent 4e2ba00120
commit 8bba9dde05
+2 -2
View File
@@ -105,12 +105,12 @@ class DPYLogger:
if not self.guild: if not self.guild:
raise ValueError(f"[dpy_logger] cannot resolve channel {self.channel} without a guild") raise ValueError(f"[dpy_logger] cannot resolve channel {self.channel} without a guild")
self.channel = await self._get_channel(self.guild) self.channel = await self._get_channel(self.guild)
if self.channel is not None and not isinstance(self.channel, (discord.TextChannel, int)):
raise ValueError(f"[dpy_logger] channel {self.channel!r} is not a text channel")
if self.guild is None and isinstance(self.channel, discord.TextChannel): if self.guild is None and isinstance(self.channel, discord.TextChannel):
self.guild = self.channel.guild self.guild = self.channel.guild
if self.guild is None and self.channel is not None: if self.guild is None and self.channel is not None:
raise ValueError("[dpy_logger] channel provided without a resolvable guild") raise ValueError("[dpy_logger] channel provided without a resolvable guild")
if self.channel is not None and not isinstance(self.channel, (discord.TextChannel, int)):
raise ValueError(f"[dpy_logger] channel {self.channel!r} is not a text channel")
async def _get_guild(self, guild): async def _get_guild(self, guild):
"""resolve a guild from id-or-object, raising if unresolvable""" """resolve a guild from id-or-object, raising if unresolvable"""