Skip to content

Commit

Permalink
fix: UserNotInitialized Error
Browse files Browse the repository at this point in the history
  • Loading branch information
royce-mathew committed Jun 14, 2024
1 parent 869e9e4 commit 3bc02a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/cogs/Moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,19 @@ async def logs(
aliases=["verify"],
)
@commands.guild_only()
@commands.cooldown(1, 1000, commands.BucketType.user)
@commands.cooldown(1, 10, commands.BucketType.user)
async def register(self, ctx: commands.Context):
author: discord.Message.author = ctx.message.author # Message Author
user_id: str = str(author.id) # Author ID converted to String
role: discord.Role = discord.utils.find(lambda r: r.name == "Verified", ctx.guild.roles) # Find verified role in the Guild

local_data = UserData.get_user_data(user_id) # Get User Data
# Check if user already has role
if (local_data := UserData.get_user_data(user_id)) is not None:
if (name := local_data.get("name", None)) is not None and name != "":
if role in author.roles:
await ctx.send(embed=create_embed("Registered", "You are already registered"))
ctx.command.reset_cooldown(ctx)
return
if (name := local_data.get("name", None)) is not None and name != "":
if role in author.roles:
await ctx.send(embed=create_embed("Registered", "You are already registered"))
ctx.command.reset_cooldown(ctx)
return


# Send initial message
bot_message: discord.Message = await ctx.send(embed=create_embed("Registration Process", "This process may take a while."))
Expand Down
5 changes: 4 additions & 1 deletion src/modules/data_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ def get_user_data_raw(user_id: bytes) -> dict:

def get_user_data(user_id: str) -> dict:
user_id_bytes = user_id.encode()
return UserData.get_user_data_raw(user_id_bytes)
try:
return UserData.get_user_data_raw(user_id_bytes)
except UserNotInitalized:
return {}

def set_user_data(user_id: str, key: str, value) -> None:
user_id_bytes = user_id.encode()
Expand Down

0 comments on commit 3bc02a5

Please sign in to comment.