From 3725ddf39c5b9fef406875bbd8c5c69ef4170290 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:30:53 +0530 Subject: [PATCH 1/2] Fix command decorator reference error Also added some missing indents. --- cogs/levelling.py | 56 +++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index 1ec8bad1..5922122d 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -69,34 +69,34 @@ async def edit_xp(self, ctx: ApplicationContext, user:discord.User, new_xp:int): await ctx.respond(f"{user.display_name}\'s XP count successfully edited. `New XP: {levels[str(user.id)]['xp']}`") except KeyError: return await ctx.respond("That user isn't indexed yet.", ephemeral=True) -@special_event.command( - name="leaderboard", - description="View the global leaderboard for user levelling ranks." -) -async def leaderboard(ctx: ApplicationContext): - levels_dict = dict() - for person in levels: - levels_dict[str(person)] = levels[str(person)]["level"] - undicted_leaderboard = sorted(levels_dict.items(), key=lambda x:x[1], reverse=True) - dicted_leaderboard = dict(undicted_leaderboard) - parsed_output = str() - y = 1 - for i in dicted_leaderboard: - if y < 10: - try: - if levels_dict[i] != 0: - user_context = await client.fetch_user(i) - if not user_context.bot and levels_dict[i] != 0: - print(i, levels_dict[i]) - if y == 1: yf = ":first_place:" - elif y == 2: yf = ":second_place:" - elif y == 3: yf = ":third_place:" - else: yf = f"#{y}" - parsed_output += f"{yf} **{user_context.name}:** level {levels_dict[i]}\n" - y += 1 - except discord.errors.NotFound: continue - localembed = discord.Embed(title="Global levelling leaderboard", description=parsed_output, color=color) - await ctx.respond(embed=localembed) + @commands.slash_command( + name="leaderboard", + description="View the global leaderboard for user levelling ranks." + ) + async def leaderboard(ctx: ApplicationContext): + levels_dict = dict() + for person in levels: + levels_dict[str(person)] = levels[str(person)]["level"] + undicted_leaderboard = sorted(levels_dict.items(), key=lambda x:x[1], reverse=True) + dicted_leaderboard = dict(undicted_leaderboard) + parsed_output = str() + y = 1 + for i in dicted_leaderboard: + if y < 10: + try: + if levels_dict[i] != 0: + user_context = await client.fetch_user(i) + if not user_context.bot and levels_dict[i] != 0: + print(i, levels_dict[i]) + if y == 1: yf = ":first_place:" + elif y == 2: yf = ":second_place:" + elif y == 3: yf = ":third_place:" + else: yf = f"#{y}" + parsed_output += f"{yf} **{user_context.name}:** level {levels_dict[i]}\n" + y += 1 + except discord.errors.NotFound: continue + localembed = discord.Embed(title="Global levelling leaderboard", description=parsed_output, color=color) + await ctx.respond(embed=localembed) def setup(bot): bot.add_cog(Levelling(bot)) From 35e98d3f17305353e4a70e25aadc51569b2e9d68 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Fri, 7 Apr 2023 22:33:00 +0530 Subject: [PATCH 2/2] Fix `fetch_user()` class object reference error --- cogs/levelling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cogs/levelling.py b/cogs/levelling.py index 5922122d..96a7a0f9 100644 --- a/cogs/levelling.py +++ b/cogs/levelling.py @@ -85,7 +85,7 @@ async def leaderboard(ctx: ApplicationContext): if y < 10: try: if levels_dict[i] != 0: - user_context = await client.fetch_user(i) + user_context = await commands.fetch_user(i) if not user_context.bot and levels_dict[i] != 0: print(i, levels_dict[i]) if y == 1: yf = ":first_place:"