如何从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)))
答案 0 :(得分:1)
Guild.bans
返回BanEntry
对象的列表。 BanEntry
是namedtuple
(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)))