尝试从guild.bans()获取用户信息

时间:2018-09-09 05:32:02

标签: python-3.x list set discord.py discord.py-rewrite

如何从guild.bans()的“用户ID”,“名称”和“鉴别符”中获取设置/列表,对于我的测试服务器,该设置/列表是[BanEntry(reason=None, user=<User id=240608458888445953 name='xpoes' discriminator='9244' bot=False>), BanEntry(reason=None, user=<User id=298265521185488896 name='Mehvix 2' discriminator='6212' bot=False>)]

我的目标是让他们能够使用此代码

newlist = []
for item in bot:
    if item:
        item = "<:bottag:473742770671058964>"
    else:
        item = ""
    newlist.append(item)
bot = newlist

total = list((zip(userid, name, discriminator, bot)))

# Thanks to happypetsy on StackOverflow for helping me with this!
pretty_list = set()
for details in total:
    data = "• <@{}>{} ({}#{}) ".format(details[0], details[3], details[1], details[2])
    pretty_list.add(data)

await ctx.message.channel.send("**Ban list:** \n{}".format("\n".join(pretty_list)))

1 个答案:

答案 0 :(得分:1)

Guild.bans返回BanEntry对象的列表。 BanEntrynamedtuple (reason, user)。我们只对user字段感兴趣。

@bot.command()
async def bans(ctx):
    bans = await ctx.guild.bans()
    pretty_list = ["• {0.id} ({0.name}#{0.discriminator})".format(entry.user) for entry in bans]
    await ctx.send("**Ban list:** \n{}".format("\n".join(pretty_list)))