Discordpy不会打印出所有成员

时间:2020-10-06 05:40:32

标签: python discord.py

我正在使用discordpy来教自己了解如何创建Discord机器人,但遇到了问题。我有一个自己的测试服务器和一个我创建的机器人。我正在尝试测试某些内容,因此我在通道中键入了一些测试文本,然后等待代码响应,但未得到响应。我决定使用guild.members检查某些内容,但返回了以下内容:

[<Member id=762523114939613204 name='MrScript-BotClone' discriminator='6549' bot=True nick=None guild=<Guild id=762530852977901619 name='bot testing grounds' shard_id=None chunked=False member_count=2>>]

这为什么也不能识别我自己的用户?

相关功能

async def check_donation(message):
    data = json.loads(message.content.split("\n")[0])
    target = message.guild.get_member_named(data["user"])
    amount = data["amount"]
    print(message.guild.members) # this is where im testing for members
    
    # call donation if member exists
    if target:
        functions.donation(target, amount)

main.py

@client.event
async def on_message(message):
    # if not in server or user is bot, ignore
    if message.author.bot or not message.guild:
        return

    # if user is not verified, start verif process
    if message.content and not await functions.is_verified(message.author):
        await generate_invite(message.author)
        await message.delete()
        return

    # setup user data if it doesn't already exist
    await functions.setup_data(message.author)

    # interpret command if starts with prefix
    if message.content.startswith(data.prefix):
        command_exists = await interpret_command(message)
        if not command_exists:
            await message.add_reaction("❌")
    
    # check if message is a donation
    if message.channel.id == data.donation_channel:
        await messages.check_donation(message)

    # check message for spam, award points and such
    await messages.handle(message)

1 个答案:

答案 0 :(得分:1)

您需要启用“成员”意图,否则不一致将不会发送成员。 您可以在https://discordpy.readthedocs.io/en/latest/intents.html上阅读意图。一个简单的示例如下:

intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)