{
"360782765890863114": {
"money": 100000000000233425,
"afk": 0
},
"364379179405410304": {
"money": -999999999999957884,
"afk": 0
},
"533112978195742721": {
"money": 0,
"afk": 0
}
У меня есть такой файл JSON.Я пытаюсь отсортировать этот файл и сделать из него команду ранга.Это весь мой код
import discord
import asyncio
import json
import operator
import sys
from discord.ext import commands
class money:
def __init__(self, bot):
self.bot = bot
self.bot.loop.create_task(self.save_users())
with open(r"/Users/gim-eunjeong/Documents/빠끔봇/cogs/users.json", 'r') as f:
self.users = json.load(f)
async def save_users(self):
await self.bot.wait_until_ready()
while not self.bot.is_closed():
with open(r"/Users/gim-eunjeong/Documents/빠끔봇/cogs/users.json", 'w') as f:
json.dump(self.users, f, indent=4)
await asyncio.sleep(5)
lines = []
def extract_money(self ,json):
try:
# Also convert to int since update_time will be string. When comparing
# strings, "10" is smaller than "2".
return int(['member_id']['money'])
except KeyError:
return 0
lines.sort(key=extract_money, reverse=True)
@commands.command()
async def 돈추가(self, ctx, member:discord.Member = None):
member = ctx.author if not member else member
member_id = str(member.id)
if ctx.author.id == 360782765890863114:
await ctx.send('얼마를 줄거야?')
def money_check(m):
return m.content.isdigit()
money_check = await self.bot.wait_for('message', check=money_check)
self.users[member_id]['money'] += int(money_check.content)
embed = discord.Embed(color=member.color, timestamp=ctx.message.created_at)
embed.set_author(name=f"money = {member}", icon_url=self.bot.user.avatar_url)
embed.add_field(name="준 돈", value=int(money_check.content))
embed.add_field(name="총 돈", value=self.users[member_id]['money'])
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="⚠ 주의", description="빠봇 오너만 사용 가능한 명령어입니다.",color=0xd8ef56)
await ctx.send(embed=embed)
@commands.command()
async def 돈제외(self, ctx, member:discord.Member = None):
member = ctx.author if not member else member
member_id = str(member.id)
if ctx.author.id == 360782765890863114:
await ctx.send('얼마를 뺄거야?')
def money_check(m):
return m.content.isdigit()
money_check = await self.bot.wait_for('message', check=money_check)
self.users[member_id]['money'] -= int(money_check.content)
embed = discord.Embed(color=member.color, timestamp=ctx.message.created_at)
embed.set_author(name=f"money = {member}", icon_url=self.bot.user.avatar_url)
embed.add_field(name="뺀 돈", value=int(money_check.content))
embed.add_field(name="총 돈", value=self.users[member_id]['money'])
await ctx.send(embed=embed)
else:
embed=discord.Embed(title="⚠ 주의", description="빠봇 오너만 사용 가능한 명령어입니다.",color=0xd8ef56)
await ctx.send(embed=embed)
@commands.command()
async def 돈지갑(self, ctx, member: discord.Member = None):
member = ctx.author if not member else member
member_id = str(member.id)
if not member_id in self.users:
await ctx.send("")
else:
embed = discord.Embed(color=member.color, timestamp=ctx.message.created_at)
embed.set_author(name=f"돈 = {member}", icon_url=self.bot.user.avatar_url)
embed.add_field(name="돈", value=self.users[member_id]['money'])
await ctx.send(embed=embed)
async def on_message(self, message):
# we do not want the bot to reply to itself
author_id = str(message.author.id)
if not author_id in self.users:
self.users[author_id] = {}
self.users[author_id]['money'] = 0
self.users[author_id]['afk'] = 0
if message.content.startswith('빠봇 돈줘'):
getmoney = random.randint(1, 10000)
await message.channel.send('{}원을 받았다고.'.format(getmoney))
self.users[author_id]['money'] += getmoney
if message.content.startswith('빠봇 숫자게임'):
await message.channel.send('얼마를 걸거야?')
def money_check(m):
return m.content.isdigit()
money_check = await self.bot.wait_for('message', check=money_check)
if int(money_check.content) > self.users[author_id]['money']:
await message.channel.send('현재 돈보다 많은 양을 걸었어')
elif int(money_check.content) < self.users[author_id]['money']:
self.users[author_id]['money'] -= int(money_check.content)
await message.channel.send('1~10 사이의 숫자를 맞춰봐')
def guess_check(m):
return m.content.isdigit()
guess = await self.bot.wait_for('message', check=guess_check)
answer = random.randint(1, 10)
print(answer)
if guess is None:
fmt = '너무 오래걸린다.. 걍 내가 말해야지 {}.'
await message.channel.send(fmt.format(answer))
return
if int(guess.content) == answer:
await message.channel.send('정답! 건 돈의 10배가 돌아왔다!')
self.users[author_id]['money'] += int(money_check.content)*10
else:
await message.channel.send('미안하지만 정답은 {}(이)라구.'.format(answer))
def setup(bot):
bot.add_cog(money(bot))


Денежный ранг (вставка) Топ 10 пользователей
1
@ 맥꾸 / 1437000 ₩
2
<@ 429549533731487754> / 833000 ₩
3
@ 잠시 왔습니 댜 곧 다시 외출 ㅌㅌ 6/628000 ₩
4
@ 맹구 / 554000 ₩
5
@ TanzenT / 512000 ₩
6
@ 한설 / 492000 ₩
7
@ 사막 여우 / 409900 ₩
8
<@ 365396996774952961> / 324000 ₩
9
<@ 461073040642670592> / 268000 ₩
10
@ {《\ 하이루 ☆ /》} / 262000 ₩
Это ожидаемые данные