Discord.py 如何通过python计算Discord服务器上的成员总数
我正在尝试此代码,但它不起作用Discord.py 如何通过python计算Discord服务器上的成员总数,discord.py,discord.py-rewrite,Discord.py,Discord.py Rewrite,我正在尝试此代码,但它不起作用 from discord.ext import commands @commands.command(pass_context=True) async def myid(ctx): print(ctx.guild.member_count) client.run(my token) 你能给我提供正确的代码吗?正如帕特里克·豪夫所说,你还没有定义你的客户。此外,在discord重写中不再需要pass_上下文 最基本的代码如下所示: from disco
from discord.ext import commands
@commands.command(pass_context=True)
async def myid(ctx):
print(ctx.guild.member_count)
client.run(my token)
你能给我提供正确的代码吗?正如帕特里克·豪夫所说,你还没有定义你的客户。此外,在discord重写中不再需要pass_上下文 最基本的代码如下所示:
from discord.ext import commands
client = commands.Bot(command_prefix = 'PREFIX')
@client.command()
async def myid(ctx):
print(ctx.guild.member_count)
client.run('TOKEN')
其中,PREFIX
是您想要的任何命令前缀,TOKEN
是您的bot令牌
我建议阅读以了解更多信息如果我们需要查找服务器的所有成员的名称,我找到了问题陈述的解决方案。然后使用这个代码
import discord
client = discord.Client()
token = 'your token'
@client.event
async def on_ready():
users = client.users
print(users)
#or
guilds = client.get_guild
for guild in client.guilds:
print(guild.name)
for member in guild.members:
print(member)
client.run(token)
这也可以工作,但发送到服务器,而不是控制台。您遇到了什么错误?@aiyan它没有响应。。。。此处未定义提交客户机的空白等待窗口。通常,
client
将是commands.Bot
的一个实例,您将使用client.command
decorator而不是commands.command
@bot.command()
async def members(ctx):
embedVar = discord.Embed(title=f'There Are {ctx.guild.member_count} Members In This Server', color=0xFF0000)
await ctx.send(embed=embedVar)