我希望这能改变机器人状态上的成员数量,但似乎无法弄清楚。
members = 31
@client.event
async def on_member_join(member):
members + 1
# updates members
@client.event
async def on_ready():
await client.change_presence(activity=discord.ActivityType.watching, name="Server Name " + str(members) + " Members!"))
答案 0 :(得分:0)
以下是一个将在多个服务器中运行的漫游器的示例:
# Excludes bots
member_count = sum([len([m for m in g.members if not m.bot]) for g in client.guilds])
# Includes bots
member_count = sum([g.member_count for g in client.guilds])
但是,如果您只是要在一台服务器上使用漫游器,那么就足够了:
# Excludes bots
member_count = len([m for m in Guild.members if not m.bot])
# Includes bots
Guild.member_count
# Side-note:
# Guild is simply the guild object that your bot is in.
# Depending on what you've called paramters -
# If you're using command decorators, you'd want ctx.guild,
# or if you're in an on_message() event, you'll want message.guild,
# or if you're somewhere else, you can use get_guild(112233445566778899)
话虽如此,第一个示例将与仅在一个服务器中的bot一起工作,但它们只是一点点的过分。
参考:
Guild.members
Guild.member_count
Guild.chunked
-如果由于任何原因而在获取会员人数方面遇到问题,您可能需要调查此问题和client.request_offline_members()
。Client.get_guild()