#πŸ”’ List of members with a specific role

37 messages Β· Page 1 of 1 (latest)

cold quarry
#

i'm trying to get a list of members with a specific role, here is what i'm attempting

            await discord.Guild.get_role(1334390638120276010)
            print(discord.Role.members)```
i keep getting this error:
Traceback (most recent call last):
  File "C:\Python\Python311\site-packages\discord\client.py", line 449, in _run_event
    await coro(*args, **kwargs)
  File "c:\main.py", line 5771, in on_message
    await discord.Guild.get_role(1334390638120276010)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Guild.get_role() missing 1 required positional argument: 'role_id'
misty ridgeBOT
#

@cold quarry

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

acoustic reef
#

well, you want to get the guild first, as get_role is a method of that
then, when you get your guild, call get_role on it, that will return the role, and the role has a members attribute
as you currently have the print, im not sure how do you expect it to print the members of the role you get above. do you just magically expect it to understand that you're referring to it?
you'd want something like

guild = client.get_guild(guild_id)
role = await guild.get_role(role_id)
print(role.members)
acoustic reef
#

also, uh, why do you have.. 6K lines in a single main.py in the root of your drive?
did you by any chance start programming the bot without any programming knowledge

cold quarry
#

Traceback (most recent call last):
File "C:\Python\Python311\site-packages\discord\client.py", line 449, in _run_event
await coro(*args, **kwargs)
File "c:\main.py", line 5772, in on_message
role = await guild.get_role(1334390638120276010)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object Role can't be used in 'await' expression

acoustic reef
cold quarry
#

yeah i worked that out LOL

cold quarry
#

is the list just empty?

acoustic reef
#

well yeah thats how an empty list is represented

cold quarry
#

yeah but 3 people have the role

#

thats why im confused

acoustic reef
#

do you have intents.members enabled?

cold quarry
#

ah maybe not?

#

do i just do intents.members = True in the bot setup?

acoustic reef
#

yep

cold quarry
#

uh oh

#

that broke a lot of things uhh

acoustic reef
#

"broke" how? is there an error message? then you should share it

cold quarry
#

yes MANY error messages...

acoustic reef
#

ah, you didnt enable the members intent in the discord bot thingy itself
well, seems like you figured it out yourself :) reading errors is useful

cold quarry
acoustic reef
#

seems like Bot > Privileged Gateway Intents > Server Members Intent
not sure if you'll also need to regenerate the oauth2 invite with it 🀷 havent really dealt with discord bots in a while

cold quarry
#

ah ty

#

i dont think so since its on the bot itself and not the auth? idk tho

#

dang maybe

#

it still prints []

#

nvm all is good now

#

didnt need to regenerate it

#

thanks dude appreciate the help

#

!close

misty ridgeBOT
#
Python help channel closed with !close

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.