如何在 discord.py rewrite 中获取成员数?

How to get the member count in discord.py rewrite?(如何在 discord.py rewrite 中获取成员数?)
本文介绍了如何在 discord.py rewrite 中获取成员数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想发出一个命令来显示成员数,但它不起作用.

I wanted to make an command to show the membercount but it doesn't work.

这就是我所拥有的:

@bot.command(name='membercount')
async def membercount(ctx):
    await ctx.send(len(guild.member_count))

这是我得到的错误:模块discord.guild"没有member_count"成员

我尝试在互联网上搜索,但没有找到可行的选项.

I tried searching on the internet but didn't find a working option.

推荐答案

虽然 Ron 的示例 确实 工作,但考虑到 ctx.guild.members 只是一个列表,这意味着您可以在其上使用 len() :

Although Ron's example does work, it is not a very elegant way considering that ctx.guild.members is just a list, meaning you can use len() on it as such:

member_count = len(ctx.guild.members) # includes bots

true_member_count = len([m for m in ctx.guild.members if not m.bot]) # doesn't include bots

另外不要忘记,如果某个答案解决了您的问题,您应该将其标记为已接受",并在其旁边使用复选标记,以向来自搜索机器的其他用户显示该问题对您有用.

Also don't forget that if an answer solved your problem, you should mark it as "accepted" with that checkmark next to it, as to show other users coming from search machines to this question, what worked for you.

这篇关于如何在 discord.py rewrite 中获取成员数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)