TotalFreedomBot/commands/help.py

59 lines
1.7 KiB
Python
Raw Normal View History

2020-10-28 11:47:39 +00:00
import math
2021-01-07 19:16:06 +00:00
import discord
2020-10-28 11:47:39 +00:00
from discord.ext import commands
2021-01-07 19:16:06 +00:00
2020-10-28 11:47:39 +00:00
from functions import get_avatar
2020-10-28 11:47:39 +00:00
class Help(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.bot.remove_command('help')
@commands.command(aliases=['h', '?'])
2020-10-28 11:47:39 +00:00
async def help(self, ctx, page=1):
2021-01-07 19:36:06 +00:00
"""Displays the help command"""
2021-01-16 18:34:46 +00:00
em = discord.Embed(
2021-01-17 00:36:28 +00:00
title='Help Command',
colour=0x00FF00,
2021-01-17 00:41:39 +00:00
)
cog_list = [c for c in self.bot.cogs.keys()]
2020-10-28 11:47:39 +00:00
page_count = math.ceil(len(cog_list) / 4)
page = int(page)
if page > page_count or page < 1:
2020-10-28 11:47:39 +00:00
await ctx.send(f'Page number \'{page}\' not found.')
return
2020-10-28 11:47:39 +00:00
cogs_needed = []
for i in range(4):
x = i + (int(page) - 1) * 4
try:
cogs_needed.append(cog_list[x])
except IndexError:
pass
2020-10-28 11:47:39 +00:00
for cog in cogs_needed:
command_list = ''
for command in self.bot.get_cog(cog).get_commands():
showcommand = True
2021-01-16 18:31:14 +00:00
if command.hidden or command.parent:
showcommand = False
for check in command.checks:
try:
check(ctx)
2021-01-07 19:36:06 +00:00
except commands.MissingPermissions:
showcommand = False
if showcommand:
command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
if command_list:
em.add_field(name=cog, value=command_list, inline=False)
em.set_footer(text=f'Requested by {ctx.message.author}', icon_url=get_avatar(
ctx.message.author))
2020-10-28 11:47:39 +00:00
await ctx.send(embed=em)
2020-10-28 11:47:39 +00:00
def setup(bot):
bot.add_cog(Help(bot))