如何在discord.py重写中获取成员数? [英] How to get the member count in discord.py rewrite?

查看:121
本文介绍了如何在discord.py重写中获取成员数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行一个命令来显示会员人数,但是它不起作用

I wanted to make an command to show the membercount but it doesnt work

这就是我所拥有的:

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

这是我得到的错误:
Module'discord .guild'没有'member_count'成员

我尝试在互联网上进行搜索,但没有找到有效的选择。

I tried searching on the internet but didnt find an 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

也不要忘记,如果答案得到解决你的问题,你应该标记我t表示为已接受,其旁边带有对勾,以表明其他来自搜索机的用户对此问题有所帮助。

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重写中获取成员数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆