Last active
May 9, 2020 11:09
-
-
Save SupremeDeity/d797b632c5f772cf8f4b6235a9351ff3 to your computer and use it in GitHub Desktop.
This is a help cog that i created for my discord bot. Change the stuff as you like, there is stuff specifically marked as # LOOK AT THIS which you might wanna change to suit your needs. NOTE: YOU MIGHT NEED TO CHANGE SOME STUFF TO MAKE IT WORK IN YOUR BOT
This file contains hidden or 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
| # SUPREMEDEITY <https://github.com/SupremeDeity> | |
| # Help Cog | |
| # NOTE: if you are not using pylint, you can remove the pylint comments. adding a __init__.py should fix the import-error problem normally, if it doesnt just keep the import | |
| # and it should still work fine. | |
| # LOOK AT THIS: | |
| # Be sure to put this line without the '#' after your commands.Bot() line, it removes the default help command | |
| # you will have already registered command errors otherwise!: | |
| # client.remove_command('help') | |
| import discord | |
| from discord.ext import commands | |
| # pylint: disable=import-error | |
| import Utils | |
| class Help(commands.Cog): | |
| """Shows this Message""" | |
| def __init__(self, client): | |
| self.client = client | |
| @commands.command() | |
| async def help(self, ctx, command=None): | |
| await ctx.message.add_reaction('ðŸ‘') | |
| if not command: | |
| embed = discord.Embed(title='Help', color=Utils.GetRandomColor()) | |
| embed.set_author(name=self.client.user.display_name, icon_url=self.client.user.avatar_url) | |
| CommandsDictonary = {} | |
| for cmd in self.client.walk_commands(): | |
| key = cmd.cog_name if cmd.cog_name else 'Uncategorized' | |
| # LOOK AT THIS: Can Run checks to see if you run the command. change this if you want to see all commands regardless of whether they can be executed by the user | |
| if Utils.can_run(cmd, ctx): | |
| # LOOK AT THIS: Its up to you to change the ``` to `. i just like the bigger one line code blocks better. | |
| CommandsDictonary.setdefault(key, []).append(f'```{cmd.name}```') | |
| # LOOK AT THIS, You might want to remove this if you wanna remove length sorting | |
| # Sort By length | |
| CommandsDictonary = dict(sorted(CommandsDictonary.items(), key= lambda x: len(x[1]), reverse=True)) | |
| for cogName, cmdName in CommandsDictonary.items(): | |
| # Removes duplicates due to aliases | |
| cmdName = list(dict.fromkeys(cmdName)) | |
| # LOOK AT THIS: You might wanna change this: this basically sets inline to true if the number of commands in Cog are > 5 or if this cog is uncategorized | |
| inline = (False if len(cmdName) > 5 or cogName == 'Uncategorized' else True) | |
| embed.add_field(name=cogName, value = f"{''.join(cmdName)}", inline=inline) | |
| embed.set_footer(text=""" | |
| You might not be seeing all commands due to permissions.\nUse +help <command> to get more information about a command.\n BOT v1.0""") | |
| await ctx.send(embed=embed) | |
| else: | |
| for x in self.client.walk_commands(): | |
| if x.name == command or command in x.aliases: | |
| embed = discord.Embed(title='Help', color=Utils.GetRandomColor()) | |
| embed.set_author(name=self.client.user.display_name, icon_url=self.client.user.avatar_url) | |
| embed.add_field(name=x.name, value=x.help, inline=False) | |
| usage = '```+{} {}```'.format(x.name, x.signature) | |
| embed.add_field(name='Usage', value=usage, inline=False) | |
| aliases = '' | |
| for y in x.aliases: | |
| aliases += "```" + str(y) + "``` " | |
| if aliases: | |
| embed.add_field(name='Aliases', value=aliases, inline=True) | |
| # LOOK AT THIS: This makes it so cant get help on commands that you cant use. You might wanna change this. | |
| if not Utils.can_run(cmd, ctx): | |
| embed.add_field(name='Note', value='```diff\n- You cannot run this command```') | |
| # LOOK AT THIS: You might wanna change this footer... | |
| embed.set_footer(text="BOT V1.0") | |
| await ctx.send(embed=embed) | |
| break | |
| def setup(client): | |
| client.add_cog(Help(client)) |
This file contains hidden or 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
| import discord | |
| from discord.ext import commands | |
| import random | |
| import json | |
| def can_run(cmd, ctx): | |
| """Our own version of checking if command can be run""" | |
| if not cmd.checks: | |
| return True | |
| else: | |
| for check in cmd.checks: | |
| try: | |
| if check(ctx): | |
| return True | |
| except: | |
| return False | |
| return False | |
| colors = { | |
| "teal": 0x1abc9c, | |
| "dark_teal": 0x11806a, | |
| "green": 0x2ecc71, | |
| "dark_green": 0x1f8b4c, | |
| "blue": 0x3498db, | |
| "dark_blue": 0x206694, | |
| "purple": 0x9b59b6, | |
| "dark_purple": 0x71368a, | |
| "magenta": 0xe91e63, | |
| "dark_magenta": 0xad1457, | |
| "gold": 0xc27c0e, | |
| "orange": 0xe67e22, | |
| "dark_orange": 0xa84300, | |
| "red": 0xe74c3c, | |
| "blurple": 0x7289da | |
| } | |
| def GetRandomColor(): | |
| # pylint: disable=no-member, unused-variable | |
| ColorName, ColorValue = random.choice(list(colors.items())) | |
| return ColorValue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment