-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelp.py
73 lines (66 loc) · 2.41 KB
/
help.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import discord
from discord.utils import utcnow
from core import Cog, Context
class HelpSelect(discord.ui.Select):
def __init__(self, cog: Cog) -> None:
super().__init__(
placeholder="Choose a category",
options=[
discord.SelectOption(
label=cog_name,
description=cog.__doc__,
)
for cog_name, cog in cog.bot.cogs.items()
if cog.__cog_commands__
and cog_name not in ["Jishaku", "Pycord", "Owner", "Help"]
],
)
self.cog = cog
async def callback(self, interaction: discord.Interaction):
cog_name = self.values[0]
assert isinstance(cog_name, str)
cog = self.cog.bot.get_cog(cog_name)
assert cog
embed = discord.Embed(
title=f"{cog_name} Commands",
description="\n".join(
f"`/{command.qualified_name}`: {command.description}" # type: ignore # description exists
for command in cog.walk_commands()
),
color=0x5865F2,
timestamp=utcnow(),
)
await interaction.response.send_message(
embed=embed,
ephemeral=True,
)
class Help(Cog):
@discord.slash_command(
integration_types={
discord.IntegrationType.guild_install,
discord.IntegrationType.user_install,
},
name="help")
async def help_command(self, ctx: Context):
"""Get help about the bot, a command or a command category."""
await ctx.defer()
assert self.bot.user
embed = discord.Embed(
title="Utility Belt",
description=(
"Welcome to Utility Belt!\n"
"Choose a category from the dropdown below to see the related commands."
),
colour=0x5865F2,
)
embed.set_thumbnail(url=self.bot.user.display_avatar.url)
embed.add_field(name="Server Count", value=str(len(self.bot.guilds)))
embed.add_field(
name="Member Count",
value=str(sum(guild.member_count for guild in self.bot.guilds)),
#value=str(len(self.bot.users)),
)
embed.add_field(name="Ping", value=f"{self.bot.latency*1000:.2f}ms")
await ctx.respond(embed=embed, view=discord.ui.View(HelpSelect(self)))
def setup(bot):
bot.add_cog(Help(bot))