Skip to content

Commit

Permalink
add check (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ableytner authored Dec 18, 2024
1 parent 51f64fd commit 94978a9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/nikobot/discord_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async def on_command_error(self,
user_command: str = exception.args[0].split('"')[1]

# call help command if command ends with '.help'
if user_command.endswith(".help"):
if discord.is_cog_loaded("help") and user_command.endswith(".help"):
help_cog = self.cogs["Help"]
# pylint: disable-next=protected-access
answer = help_cog._generate_help_specific_normal(user_command.replace(".help", ""))
Expand Down
5 changes: 5 additions & 0 deletions src/nikobot/util/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ def _remove_type_hints(signature: str) -> str:

return ", ".join(args)

def is_cog_loaded(name: str) -> bool:
"""Checks whether the cog with the given name is loaded"""

return name.lower() in (cog.lower() for cog in get_bot().cogs)

def is_private_channel(ctx: commands.context.Context | discordpy.interactions.Interaction) -> bool:
"""Checks whether the message related to ``ctx`` was received as a private / direct message"""

Expand Down

0 comments on commit 94978a9

Please sign in to comment.