Answer a question

I've got a question, I need to get a list from all members from all servers where the bot is online(I'm using discord.py rewrite), Right now I have this code-snipped:

@bot.command()
async def members(ctx):
    for guild in bot.guilds:
        for member in guild.members:
            print(member)

The program outputs the Bots name 3 times because the bot is on 3 servers.

Thank you!

Answers

Sounds like an Intents issue. You need to enable the members intent when creating your commands.Bot instance, and pass your intents into it.

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

client = commands.Bot(intents=intents, prefix_and_other_things_go_here)

You also have to enable it in your developer portal. More info on how & where: https://discordpy.readthedocs.io/en/latest/intents.html

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐