Discord.py 机器人公会数

Discord.py bot guild count

我正在尝试获取我的机器人所在的公会数量,这是我当前的代码:

@client.command()
async def servers(ctx):
    await ctx.send(f"{str(client.guilds)}")

但机器人只是响应 [<Guild id=739683588408082462 name='Epic bot testing' shard_id=None chunked=True member_count=17>] 我该如何解决这个问题?

client.guilds 是公会列表,因此您只需将 str 更改为 len 即可获得该列表的长度。

@client.command()
async def servers(ctx):
    await ctx.send(f"{len(client.guilds)}")