【发布时间】:2020-09-22 04:21:53
【问题描述】:
所以,我正在使用 discord.py 制作一个 Discord 机器人,这是我的代码:
@bot.command()
async def list(ctx):
ok = 0
for i in db.keys():
# lmao why is there even a while loop here @
while ok >= 11:
server_num = ok+1
em = discord.Embed(title='Oldest servers in the list!',description=f'Server {server_num}')
em.add_field(name='Name',value=db[i]['name'],inline=False)
em.add_field(name='Description',value=db[i]['description'],inline=False)
em.add_field(name='Tags',value=db[i]['tags'],inline=False)
await ctx.send(embed=em)
ok+=1
但是,我还想要的是它返回支持最多的服务器,我们有一个支持系统,它的代码是:
@bot.command()
@commands.cooldown(1,7200)
async def upvote(ctx):
try:
id = str(ctx.message.guild.id)
if id in db.keys():
db[id]["upvote"][0] += 1
await ctx.send(f"upvoted ")
save()
except commands.CommandOnCooldown:
await ctx.send('once every 12 hours ;---------------;')
except:
await ctx.send('error ;-;')
而且,每个赞成票都存储在一个 JSON 文件 (db.json) 中,如下所示:
{
"738049816357109831": {
"description": "I am a good server",
"id": "738049816357109831",
"link": "https://discord.gg/gQ6FABc",
"name": "Aypro's Lab",
"review(s)": [],
"tags": [
"#good_boi"
],
"upvote": [
0
]
}
}
而且我不确定如何获得最多票数的服务器。感谢谁会回答这个问题,因为它将真正帮助我开发机器人。
【问题讨论】:
标签: python json python-3.x discord discord.py