【问题标题】:Trying to get user info from guild.bans()试图从 guild.bans() 获取用户信息
【发布时间】:2019-02-13 22:25:36
【问题描述】:

我如何从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)))

【问题讨论】:

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


    【解决方案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)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-23
      • 1970-01-01
      • 2017-01-02
      • 2021-03-09
      • 2015-09-22
      相关资源
      最近更新 更多