help_start.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import json
  2. from pathlib import Path
  3. import discord
  4. from discord.ext import commands
  5. from discord.commands import Option
  6. from discord.commands import slash_command
  7. class helpstart(commands.Cog):
  8. def __init__(self, bot: discord.Bot):
  9. self.bot = bot
  10. #Command initialization
  11. @slash_command(name="help_start", description= "Get Infos how to start playing on the server")
  12. async def help_start(self,ctx: discord.ApplicationContext,
  13. ):
  14. server = ctx.guild
  15. json_path = Path(__file__).resolve().parent / "json_files" / "help_start.json"
  16. if not json_path.exists():
  17. await ctx.respond("The .json file is missing.")
  18. return
  19. try:
  20. with json_path.open("r", encoding="utf-8") as f:
  21. json_data = json.load(f)
  22. except json.JSONDecodeError:
  23. await ctx.respond("The .json file is not valid JSON.")
  24. return
  25. if isinstance(json_data, dict):
  26. entries = [json_data]
  27. elif isinstance(json_data, list):
  28. entries = json_data
  29. else:
  30. await ctx.respond("The .json file has an unexpected structure.")
  31. return
  32. if not entries or not isinstance(entries[0], dict):
  33. await ctx.respond("The .json file has an unexpected structure.")
  34. return
  35. if not entries:
  36. await ctx.respond("The .json file is empty.")
  37. return
  38. entry = entries[0]
  39. jstitle = entry.get("title", "Help")
  40. jsdesc = entry.get("desc", "No description provided.")
  41. embed = discord.Embed(
  42. title=f"{jstitle}",
  43. description=f"{jsdesc}",
  44. color=discord.Color.yellow()
  45. )
  46. embed.set_thumbnail(url=server.icon)
  47. embed.set_author(name="VicePD", icon_url="https://i.imgur.com/6QteFrg.png")
  48. embed.set_footer(text="VicePD - Bot | Made by BaumSplitter41")
  49. await ctx.respond(embed=embed)
  50. def setup(bot: discord.Bot):
  51. bot.add_cog(helpstart(bot))