Skip to content

Commit

Permalink
新增指令 !level
Browse files Browse the repository at this point in the history
  • Loading branch information
tooruche520 committed Oct 14, 2022
1 parent cbedbbd commit 0b69851
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cogs/LevelSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ async def on_message(self, message):
with open('users.json', "w", encoding = "utf8") as f:
json.dump(users, f)



@commands.command()
async def level(self, ctx):
try:
with open('users.json', "r", encoding = "utf8") as f:
users = json.load(f)
user_id = str(ctx.author.id)
experience = users[user_id]['experience']
level = users[user_id]['level']
await ctx.send(f'{ctx.author.mention} 目前是等級{level},累積了{experience}經驗值!!')
except Exception as e:
log.info("Error loading users.json")

# 要用 async await
async def setup(bot):
await bot.add_cog(LevelSystem(bot))

0 comments on commit 0b69851

Please sign in to comment.