問(wèn)題描述
您好,我正在創(chuàng)建一個(gè)制作積分表/排行榜的機(jī)器人,下面是非常好用的代碼.
Hi I am creating a bot that makes points table/leaderboard , below is the code which works really nice.
def check(ctx):
return lambda m: m.author == ctx.author and m.channel == ctx.channel
async def get_input_of_type(func, ctx):
while True:
try:
msg = await bot.wait_for('message', check=check(ctx))
return func(msg.content)
except ValueError:
continue
@bot.command()
async def start(ctx):
await ctx.send("How many total teams are there?")
t = await get_input_of_type(int, ctx)
embed = discord.Embed(title=f"__**{ctx.guild.name} Results:**__", color=0x03f8fc,timestamp= ctx.message.created_at)
lst = []
for i in range(t):
await ctx.send(f"Enter team {i+1} name :")
teamname = await get_input_of_type(str, ctx)
await ctx.send("How many kills did they get?")
firstnum = await get_input_of_type(int, ctx)
await ctx.send("How much Position points did they score?")
secondnum = await get_input_of_type(int, ctx)
lst.append((teamname, firstnum, secondnum)) # append
lstSorted = sorted(lst, key = lambda x: int(x[1]) + int(x[2],),reverse=True) # sort
for teamname, firstnum, secondnum in lstSorted: # process embed
embed.add_field(name=f'**{teamname}**', value=f'Kills: {firstnum}
Position Pt: {secondnum}
Total Pt: {firstnum+secondnum}',inline=True)
await ctx.send(embed=embed)
結(jié)果如下所示:
但我想知道,我可以做些什么來(lái)獲得表格形式的結(jié)果,例如團(tuán)隊(duì)名稱、位置點(diǎn)數(shù)、總分、連續(xù)寫(xiě)的擊殺分以及打印在它們下面的結(jié)果(我真的不知道,如果這讓你明白我想說(shuō)什么.)
But I want to know, can I do something to get the result in tabular form like The Team Name , positions points , total pts, kill pts written in a row and the results printed below them (I really don't if that made you understand what I am trying to say.)
下圖幫助你理解,
所以我希望結(jié)果采用以下格式.我想不出辦法,如果你能回答這個(gè)問(wèn)題,請(qǐng)這樣做,那將是一個(gè)非常大的幫助!謝謝.
So I want the result to be in following format. I can't think of a way doing it , if you can answer this please do so, That would be a very great help! Thanks.
推薦答案
這可能是你得到的最接近的:
This is probably the closest you will get:
embed.add_field(name=f'**{teamname}**', value=f'> Kills: {firstnum}
> Position Pt: {secondnum}
> Total Pt: {firstnum+secondnum}',inline=False)
代碼將輸出如下內(nèi)容:
我已將 inline
設(shè)置為 False
并將 >
字符添加到每個(gè)統(tǒng)計(jì)信息中.
I've set inline
to False
and added the >
character to each of statistics.
這篇關(guān)于如何使數(shù)據(jù)在 discord.py 中以表格形式顯示?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!