@@ -86,7 +86,24 @@ async def channel_stats(
8686 # NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent
8787 main_guild : discord .Guild = self .bot .main_guild
8888
89- channel_id : int = ctx .channel_id
89+ match ctx .channel :
90+ case None :
91+ CTX_CHANNEL_IS_NONE_MESSAGE : Final [str ] = (
92+ "Cannot send stats graph when `ctx.channel` is `None`."
93+ )
94+ raise TypeError (CTX_CHANNEL_IS_NONE_MESSAGE )
95+ case discord .ForumChannel () | discord .CategoryChannel ():
96+ await self .command_send_error (
97+ ctx ,
98+ message = (
99+ f"The `/{ ctx .command } ` command cannot be used in the channel: {
100+ ctx .channel .mention
101+ } "
102+ ),
103+ )
104+ return
105+
106+ channel_id : int | None = ctx .channel_id
90107
91108 if str_channel_id :
92109 if not re .fullmatch (r"\A\d{17,20}\Z" , str_channel_id ):
@@ -97,6 +114,12 @@ async def channel_stats(
97114
98115 channel_id = int (str_channel_id )
99116
117+ if channel_id is None :
118+ CTX_CHANNEL_ID_IS_NONE_MESSAGE : Final [str ] = (
119+ "Cannot produce stats graph when `ctx.channel_id` is `None`."
120+ )
121+ raise TypeError (CTX_CHANNEL_ID_IS_NONE_MESSAGE )
122+
100123 channel : discord .TextChannel | None = discord .utils .get (
101124 main_guild .text_channels , id = channel_id
102125 )
@@ -157,6 +180,23 @@ async def server_stats(self, ctx: "TeXBotApplicationContext") -> None:
157180 main_guild : discord .Guild = self .bot .main_guild
158181 guest_role : discord .Role = await self .bot .guest_role
159182
183+ match ctx .channel :
184+ case None :
185+ CTX_CHANNEL_IS_NONE_MESSAGE : Final [str ] = (
186+ "Cannot send stats graph when `ctx.channel` is `None`."
187+ )
188+ raise TypeError (CTX_CHANNEL_IS_NONE_MESSAGE )
189+ case discord .ForumChannel () | discord .CategoryChannel ():
190+ await self .command_send_error (
191+ ctx ,
192+ message = (
193+ f"The `/{ ctx .command } ` command cannot be used in the channel: {
194+ ctx .channel .mention
195+ } "
196+ ),
197+ )
198+ return
199+
160200 await ctx .defer (ephemeral = True )
161201
162202 message_counts : Mapping [str , Mapping [str , int ]] = await get_server_message_counts (
@@ -248,6 +288,23 @@ async def user_stats(self, ctx: "TeXBotApplicationContext") -> None:
248288 )
249289 return
250290
291+ match ctx .channel :
292+ case None :
293+ CTX_CHANNEL_IS_NONE_MESSAGE : Final [str ] = (
294+ "Cannot send stats graph when `ctx.channel` is `None`."
295+ )
296+ raise TypeError (CTX_CHANNEL_IS_NONE_MESSAGE )
297+ case discord .ForumChannel () | discord .CategoryChannel ():
298+ await self .command_send_error (
299+ ctx ,
300+ message = (
301+ f"The `/{ ctx .command } ` command cannot be used in the channel: {
302+ ctx .channel .mention
303+ } "
304+ ),
305+ )
306+ return
307+
251308 await ctx .defer (ephemeral = True )
252309
253310 message_counts : dict [str , int ] = {"Total" : 0 }
@@ -314,6 +371,23 @@ async def left_member_stats(self, ctx: "TeXBotApplicationContext") -> None:
314371 # NOTE: Shortcut accessors are placed at the top of the function so that the exceptions they raise are displayed before any further errors may be sent
315372 main_guild : discord .Guild = self .bot .main_guild
316373
374+ match ctx .channel :
375+ case None :
376+ CTX_CHANNEL_IS_NONE_MESSAGE : Final [str ] = (
377+ "Cannot send stats graph when `ctx.channel` is `None`."
378+ )
379+ raise TypeError (CTX_CHANNEL_IS_NONE_MESSAGE )
380+ case discord .ForumChannel () | discord .CategoryChannel ():
381+ await self .command_send_error (
382+ ctx ,
383+ message = (
384+ f"The `/{ ctx .command } ` command cannot be used in the channel: {
385+ ctx .channel .mention
386+ } "
387+ ),
388+ )
389+ return
390+
317391 await ctx .defer (ephemeral = True )
318392
319393 left_member_counts : dict [str , int ] = {
0 commit comments