【发布时间】:2020-12-13 09:01:55
【问题描述】:
您好,我正在创建一个制作积分表/排行榜的机器人,下面的代码非常好用。
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}\nPosition Pt: {secondnum}\nTotal Pt: {firstnum+secondnum}',inline=True)
await ctx.send(embed=embed)
结果如下所示:
但我想知道,我可以做些什么来获得表格形式的结果,比如团队名称、位置点、总分、连续写的击杀分以及打印在它们下面的结果(我真的不知道,如果这让你明白我想说什么。)
下图帮助你理解,
所以我希望结果采用以下格式。我想不出办法,如果你能回答这个问题,请这样做,那将是一个非常大的帮助! 谢谢。
【问题讨论】:
标签: python discord discord.py