基本Discord Python程序-guild.members未将所有成员添加到数组

时间:2020-10-22 05:48:00

标签: python discord discord.py

我有以下代码:

import os
import discord
from dotenv import load_dotenv

load_dotenv()
TOKEN = os.getenv("DISCORD_TOKEN")
GUILD = os.getenv("DISCORD_GUILD")

client = discord.Client()

@client.event
async def on_ready():
    for guild in client.guilds:
        if guild.name == GUILD:
            break

    print(f"{client.user} is connected to the following guild:\n"
            f"{guild.name}(id: {guild.id})")

    print(guild.members)
    members = "\n - ".join([member.name for member in guild.members])
    print(f"Guild Members:\n - {members}")

@client.event
async def on_member_join(member):
    print("reached event")
    await member.create_dm()
    await member.dm_channel.send(f"Hi {member.name}, welcome to jeopardy")

client.run(TOKEN)
    

这直接来自我正在关注的教程。但是,当我运行它时,它显示:

{bot name} is connected to the following guild:
{guild name}(id: {id})
[<Member id={member id} name='{name}' discriminator='{disc}' bot=True nick=None guild=<Guild id={id} name="{name}" shard_id=None chunked=False member_count=2>>]
Guild Members:
 - {bot name}

如您所见,该代码在线显示2个成员,但仅将其自身添加到member数组。此外,它不会检测新用户何时加入。为什么会这样?

0 个答案:

没有答案