Discord bot不返回所有成员

2024-06-16 14:43:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在创建一个discord bot,并想添加!server命令来查看服务器信息。我添加了members部分,但它返回1,但我的服务器有2个人类成员和4个机器人(都是我的),为什么?这是代码:

@bot.command()
async def server(ctx):
    membersInServer = ctx.guild.members
    botsInServer = list(filter(filterOnlyBots, membersInServer))
    serv_emb = discord.Embed(title = f'Info about server {ctx.guild.name}')
    serv_emb.add_field(name = 'Members', value = f'All: {len(membersInServer)}\nBots: {len(botsInServer)}')
    await ctx.send(embed = serv_emb)

Tags: name命令服务器信息lenserverbotctx
1条回答
网友
1楼 · 发布于 2024-06-16 14:43:33

我建议不要依赖旧版本的discord.py,因为这可能会阻止您将来访问新功能和错误修复

首先,通过转到https://discord.com/developers/applications/<app_id>/bot并选中“服务器成员意图”,在Discord应用程序上启用成员特权意图

然后,按以下方式使用成员意图:

import discord

intents = discord.Intents(members=True)
client = commands.Bot(command_prefix="!", intents=intents)

# The remainder of your code...

你准备好出发了

相关问题 更多 >