|
|
@@ -1,5 +1,5 @@
|
|
|
import json
|
|
|
-import os
|
|
|
+from pathlib import Path
|
|
|
import discord
|
|
|
from discord.ext import commands
|
|
|
from discord.commands import slash_command
|
|
|
@@ -13,20 +13,37 @@ class helpteam(commands.Cog):
|
|
|
async def help_team(self, ctx: discord.ApplicationContext):
|
|
|
server = ctx.guild
|
|
|
|
|
|
- #Loading the JSON file
|
|
|
- JSON_FILE_PATH = 'cogs/json_files/help_team.json'
|
|
|
- if not os.path.exists(JSON_FILE_PATH):
|
|
|
+ json_path = Path(__file__).resolve().parent / "json_files" / "help_team.json"
|
|
|
+ if not json_path.exists():
|
|
|
await ctx.respond("The help_team.json file is missing.")
|
|
|
return
|
|
|
- with open(JSON_FILE_PATH, 'r', encoding='utf-8') as f:
|
|
|
- json_data = json.load(f)
|
|
|
|
|
|
- for entry in json_data:
|
|
|
- jstitle = entry.get("title", "")
|
|
|
- jsdesc = entry.get("desc", "")
|
|
|
+ try:
|
|
|
+ with json_path.open("r", encoding="utf-8") as f:
|
|
|
+ json_data = json.load(f)
|
|
|
+ except json.JSONDecodeError:
|
|
|
+ await ctx.respond("The help_team.json file is not valid JSON.")
|
|
|
+ return
|
|
|
|
|
|
+ if isinstance(json_data, dict):
|
|
|
+ entries = [json_data]
|
|
|
+ elif isinstance(json_data, list):
|
|
|
+ entries = json_data
|
|
|
+ else:
|
|
|
+ await ctx.respond("The help_team.json file has an unexpected structure.")
|
|
|
+ return
|
|
|
|
|
|
+ if not entries or not isinstance(entries[0], dict):
|
|
|
+ await ctx.respond("The help_team.json file has an unexpected structure.")
|
|
|
+ return
|
|
|
+
|
|
|
+ if not entries:
|
|
|
+ await ctx.respond("The help_team.json file is empty.")
|
|
|
+ return
|
|
|
|
|
|
+ entry = entries[0]
|
|
|
+ jstitle = entry.get("title", "Help Team")
|
|
|
+ jsdesc = entry.get("desc", "No description provided.")
|
|
|
|
|
|
embed = discord.Embed(
|
|
|
title=f"{jstitle}",
|