Guest User

Untitled

a guest
Jun 26th, 2024
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.12 KB | None | 0 0
  1. @commands.slash_command(
  2.     name = "help",
  3.     description = "Returns a paginator embed of all available bot commands based off your top role",
  4.     guild_ids=[JsonService().get_guild_id()]
  5. )
  6. @commands.has_any_role("member")
  7. async def help(self, inter):
  8.     await inter.response.defer(ephemeral=True)
  9.  
  10.     gen_commands = self.json_service.get_gen_commands()
  11.     staff_commands = self.json_service.get_staff_commands()
  12.  
  13.     owner_role_id = self.json_service.get_owner_id()
  14.     admin_role_id = self.json_service.get_admin_id()
  15.     mod_role_id = self.json_service.get_mod_id()
  16.  
  17.     user_top_role_id = inter.author.top_role.id
  18.  
  19.     embed = disnake.Embed(
  20.         color = disnake.Colour.random(),
  21.         title = f"{inter.guild.name}'s Help Command",
  22.         description = "In the following pages you will see the help commands available to you based off your highest ranking role."
  23.     ).set_footer(
  24.         text = "If you encounter problems with this command, please run `/report`"
  25.     ).set_thumbnail(url = inter.guild.icon)
  26.  
  27.     gen_embeds = self.build_embeds(gen_commands)
  28.     staff_embeds = self.build_embeds(staff_commands)
  29.  
  30.     all_embeds = [embed]
  31.  
  32.     if user_top_role_id in [owner_role_id, admin_role_id, mod_role_id]:
  33.         all_embeds.append(gen_embeds)
  34.         all_embeds.append(staff_embeds)
  35.     else:
  36.         all_embeds.append(gen_embeds)
  37.  
  38.     return await inter.edit_original_message(
  39.         embed = all_embeds[0],
  40.         view = Pagination(
  41.             embeds = all_embeds
  42.         )
  43.     )
  44.  
  45. def build_embeds(self, list_of_commands):
  46.     return_embeds = []
  47.  
  48.     for item in list_of_commands:
  49.         name = item
  50.         action = list_of_commands[item]["command"]
  51.         descr = list_of_commands[item]["description"]
  52.         examples = '\n'.join(list_of_commands[item]["examples"])
  53.  
  54.         embed = disnake.Embed(
  55.             color = disnake.Colour.random(),
  56.             title = name,
  57.             description = descr
  58.         ).add_field(
  59.             name = action,
  60.             value = examples,
  61.             inline = False
  62.         )
  63.  
  64.         return_embeds.append(embed)
  65.  
  66.     return return_embeds
Advertisement
Add Comment
Please, Sign In to add comment