Skip to content

Commit

Permalink
Fix double level-up race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
WitherredAway authored Oct 6, 2024
1 parent 9611837 commit 8d8cb36
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cogs/levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@ async def on_message(self, message):

roles = [message.guild.get_role(x) for x in ROLES[new_level]]
await message.author.add_roles(*roles)
await self.bot.mongo.db.member.update_one(
{"_id": {"id": message.author.id, "guild_id": message.guild.id}},
u = await self.bot.mongo.db.member.update_one(
{"_id": {"id": message.author.id, "guild_id": message.guild.id}, "level": user.get("level", None)},
{"$inc": {"level": 1}},
)
if not u.modified_count:
return

msg = f"Congratulations {message.author.mention}, you are now level **{new_level}**!"
for role in roles:
Expand Down

0 comments on commit 8d8cb36

Please sign in to comment.