How to get users in role specified in channel
Question:
I’m using discord.py
2.1.0, and I want to get users with role id specified in text channel.
I am trying this approach, but it does not work:
role = discord.utils.get(channel.guild.roles, id=1060070158267326565)
users = role.members
print(users)
output :
[]
Answers:
Seems like you either did not enable the required intent, or there is actually no members with this role.
For intents, check the discord developers portal and enable them. Don’t forget to do it in your code too.
I don’t see any problems in your code.
Try to give the bot that role and see, if it returns your bot then:
- Make sure that
guild_members
intent is enabled in the dashboard.
Also your code should contain:
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(intents=intents)
I’m using discord.py
2.1.0, and I want to get users with role id specified in text channel.
I am trying this approach, but it does not work:
role = discord.utils.get(channel.guild.roles, id=1060070158267326565)
users = role.members
print(users)
output :
[]
Seems like you either did not enable the required intent, or there is actually no members with this role.
For intents, check the discord developers portal and enable them. Don’t forget to do it in your code too.
I don’t see any problems in your code.
Try to give the bot that role and see, if it returns your bot then:
- Make sure that
guild_members
intent is enabled in the dashboard.
Also your code should contain:
intents = discord.Intents.default()
intents.members = True
client = commands.Bot(intents=intents)