-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added the reload extension command #285
Merged
+71
−7
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
|
||
# Imports. | ||
|
||
|
||
from disnake.ext import commands | ||
from disnake.ext.commands import errors | ||
|
||
import core | ||
|
||
|
||
class Admin(commands.Cog): | ||
@commands.command(name='reloadext') | ||
async def reload_extension( | ||
self, ctx: commands.Context[core.IgKnite], name: str | ||
) -> None: | ||
try: | ||
ctx.bot.reload_extension(name) | ||
except Exception as e: | ||
if isinstance(e, errors.ExtensionNotLoaded): | ||
msg = f'`{name}` extension is not loaded.' | ||
elif isinstance(e, errors.ExtensionNotFound): | ||
msg = f'No extension with name `{name}` exists.' | ||
elif isinstance(e, errors.ExtensionFailed): | ||
msg = f'Failed to load `{name}` extension.' | ||
elif isinstance(e, errors.NoEntryPointError): | ||
msg = f'Setup function is not defined in `{name}` file.' | ||
# getting here shouldnt happen, just making sure msg | ||
# doesnt have an Unbound type. | ||
else: | ||
msg = f'Something went wrong while loading `{name}` extension.' | ||
|
||
embed = core.TypicalEmbed(description=msg, is_error=True) | ||
await ctx.send(embed=embed) | ||
else: | ||
embed = core.TypicalEmbed( | ||
description=f'Successfully reloaded `{name}` extension.' | ||
) | ||
await ctx.send(embed=embed) | ||
|
||
@reload_extension.error | ||
async def reload_ext( | ||
self, ctx: commands.Context[core.IgKnite], error: errors.CommandError | ||
) -> None: | ||
if isinstance(error, errors.MissingRequiredArgument): | ||
embed = core.TypicalEmbed( | ||
description='Please provide an extension name.', is_error=True | ||
) | ||
await ctx.send(embed=embed) | ||
# a check failure would be raised when someone who is not | ||
# an owner uses the command but we dont wanna catch it, | ||
# since we dont wanna send any messages if someone who | ||
# isn't an owner uses the command. | ||
|
||
async def cog_check(self, ctx: commands.Context[core.IgKnite]) -> bool: | ||
return await ctx.bot.is_owner(ctx.author) | ||
|
||
|
||
def setup(bot: core.IgKnite) -> None: | ||
bot.add_cog(Admin()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @hitblast this should be @commands.slash_commands right?
@iyad-f , Can you provide a example of how to use this command. I am not able to use this command. Wanted to know if there is any other way of using command than "slash"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is not going to be a slash command since we don't wanna go with the overhead of registring it to just one guild where admins is present, we rather go with a prefixed command which only owners of the bot will be able to use. As for the second part of the question how to use this, its simple ?reloadext <extiontion_path> e.g. ?reloadext cogs.admin