2
2
20two.may2020-11-20 08:22:12
Python
20two.may, 2020-11-20 08:22:12

The function with viewing all server users does not work. What is the problem?

Hello. In general, you need to display the nickname of each user on the server in the console.
I am using this loop:

@bot.event
async def on_ready():
  for guild in bot.guilds:
    for member in guild.members:
      print(member)


But it doesn't work, i.e. displays ONLY the name of the bot in the console, while not giving any errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
2
20two.may, 2020-11-20
@20two_may

In general, I solved the problem.
The point was that Discord introduced Intents . This is a radical change in how bots are written. The intent basically allows the bot to subscribe to certain event segments. The events corresponding to each intent are documented in a separate intent documentation attribute.
To get started, you need to:
1. Go to discord.com/developers
2. Select your App
3. Go to the Bot section
4. Scroll to Privileged Gateway Intents and enable two items there.
After granting these "permissions" in Discord Developers, they must also be granted in the code itself and confirmed there, in my case it looked like this:

intents = discord.Intents(messages=True, guilds=True, members=True)
bot = commands.Bot(command_prefix = "-", intents=intents)

After that, everything worked fine for me.
Well, to get a list of all server users, I also decided to use a newer "version" of the cycle that I had at the very beginning. Now it looks like this:
@bot.event
async def on_ready():
for member in bot.get_all_members():
    print(member)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question