Skip to content

Commit 335b8e5

Browse files
committed
fix(afk): update command invocation checks to use interaction_metadata
- Refactored the command invocation logic to prioritize `interaction_metadata` over the deprecated `interaction` attribute, improving compatibility and future-proofing the code. - Enhanced logging to provide better visibility when ignoring self_timeout command responses, ensuring clearer debugging information.
1 parent bfb6f6b commit 335b8e5

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/tux/modules/utility/afk.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -298,18 +298,23 @@ async def check_afk(self, message: discord.Message) -> None:
298298
# Check for prefix commands
299299
if message.content.startswith(f"{prefix}sto"):
300300
return
301-
# Check for slash command invocations
302-
if (
303-
message.interaction
304-
and message.interaction.command
305-
and message.interaction.command.name
306-
in (
307-
"self_timeout",
308-
"sto",
309-
"stimeout",
310-
"selftimeout",
311-
)
301+
# Check for slash command invocations (prefer interaction_metadata; interaction is deprecated)
302+
command_name: str | None = None
303+
if message.interaction_metadata:
304+
command_name = getattr(message.interaction_metadata, "name", None)
305+
elif hasattr(message, "interaction") and message.interaction is not None:
306+
cmd = getattr(message.interaction, "command", None)
307+
command_name = getattr(cmd, "name", None) if cmd else None
308+
if command_name and command_name in (
309+
"self_timeout",
310+
"sto",
311+
"stimeout",
312+
"selftimeout",
312313
):
314+
logger.debug(
315+
"Ignoring self_timeout command response from %s",
316+
message.author.id,
317+
)
313318
return
314319

315320
afks_mentioned: list[tuple[discord.Member, AFKMODEL]] = []

0 commit comments

Comments
 (0)