Get all Memebers with a certain Role - python

I have been trying for quite some time to get a list of all members with a specific role, but I fail every time.
I know that there is role.members but I have no idea how to use it in order to get a list of all members with a specific role.
I have looked through many questions (to get a list of members with a specific role) here on Stack Overflow, but I was not able to find a working solution
How can I get a list of all members with a specific role?

If you are sure role is a discord.Role model, role.members should return a List of members. I assume you are getting an empty list, if it is then you are probably missing Member Intents to see the members of a Role and this is probably the reason you are only getting an empty list.
Discord.py has it is own explanation about this topic that you can read here.
(Also, i saw that discord.py didn't mention it but if you want to turn on all of the intents rather than specifying it, you can use discord.Intents.all method to make an intent that has everything turned on in it.)

Related

Trouble getting all the user ids in a discord server using a Hikari bot

I am trying to code an exp leveling system in my discord bot and everything is done but one part i need to be able to get every single member of a guild when i join it but the problem is when i get the guild with event.guild.get_members() and try to iterate through it with for member in members: it tells me that it cant be iterated because its type snowflake which is the base class and i cant find any method any where to turn event.guild.get_members() into member objects that i can get the userid from to put them in the database. If anyone has any methods to find all the user ids in the guild that would also work so if you have that i would count that as an answer.

discord.py how to get a list of members with a specific role?

I need to get a list of participants with a special role on the server, so that I can send them messages.Who knows how this could be done please help me, I tried to find an answer to this question, but nothing works
See the documentation for discord.Role.members.

Is there a way to get the id's of all members who are connected to a voice channel in a guild?

Every way I found on the internet apparently doesn't work anymore with the latest Discord.py version.
If there is no way, is there a way to get all voice-channel id's? This would also fit what I want to achieve. I cant provide code since I deleted everything I've tried but I tried for two hours.
To start with you need a VoiceChannel object.
Once you have this object, you can use the members attribute to get a list of members that are connected to the voice channel. You can then access the member objects one by one getting the ids.
Example:
member_ids = []
for member in voice_channel.members
member_ids.append(member.id)

Discord.py get user with Name#0001

How do I get the user/member object in discord.py with only the Name#Discriminator? I searched now for a few hours and didn't find anything. I know how to get the object using the id, but is there a way to convert Name#Discriminator to the id?
The user may not be in the Server.
A bot can only get a User instance, that it isn't in a server with, from a unique ID.
You can use both discord.utils.get and get_all_members to get a Member using your input though:
member = discord.utils.get(bot.get_all_members(), name='name', discriminator='discriminator')
# discriminator should not contain #
P.S afaik utils.get takes any kwarg that could be an attribute for a class
There's no way to do it if you aren't sure they're in the server. If you are, you can search through the servers' members, but otherwise, it wouldn't make sense. Usernames/Discriminators change all the time, while IDs remain unique, so it would become a huge headache trying to implement that. Try doing what you want by ID, or searching the server.

Discord.py - How to track if someone joined from a specific invite?

I'm trying to figure out how to see who joined from a specific invite within my guild - is this possible? The end goal is for the bot to grant a role to a user if they joined from a specific invite, and grant a seperate role if they joined from a different invite
Yes, it is, but you'll have to do the heavy lifting.
Here's the reference for the Invite object. It has a uses attribute which stores the amount of times it's been used to join your server: so if you store all the possible invites for your server in memory, and check which one went up whenever a user joins (in on_member_join(), you'll be able to tell which one they used.
This medium article shows a way to do it. There's no other way I'm aware of, or that I can find in the documentation.

Categories