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!
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
Your code is correct. However you require the Members Intent
You will have to enable it here. Select the application you want it on -> Select Bot
-> SERVER MEMBERS INTENT and then make sure it shows blue next to it. Then click Save Changes. Since you are developing your bot you might want to enable Presence intent as well to save you time later.
You will then have to edit your bot variable like so:
intents = discord.Intents()
intents.all()
bot = commands.Bot(command_prefix=".", intents=intents)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With