問題描述
我想發出一個命令來顯示成員數,但它不起作用.
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 中獲取成員數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!