【问题标题】:Discord bot dont return all membersDiscord bot 不返回所有成员
【发布时间】:2021-02-15 01:51:07
【问题描述】:

我制作了一个不和谐的机器人,并想添加!server 命令来查看服务器信息。我添加了成员​​部分,但它返回 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)

【问题讨论】:

标签: python discord discord.py-rewrite


【解决方案1】:

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

首先,通过转到https://discord.com/developers/applications/<app_id>/bot 并选中“SERVER MEMBERS INTENT”,在您的 Discord 应用程序上启用 Members 特权 Intent。

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

import discord

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

# The remainder of your code...

你已经准备好开始了!

【讨论】:

    猜你喜欢
    • 2021-08-11
    • 2021-06-25
    • 2021-01-20
    • 2021-07-19
    • 1970-01-01
    • 2020-08-19
    • 2021-05-05
    • 2021-02-07
    • 2020-07-31
    相关资源
    最近更新 更多