0

I am trying to create a function of my discord bot where on a command it prints the names of online members in a specific channel to the chat. I can get the bot to print all members of a channel but cannot get it to isolate only the online members.

My current code is thus

linkchannel = int(message.channel.topic)
        channel = client.get_channel(linkchannel)
        members = channel.members 
    
        names = [] #(list)
        for member in members:
          if member.Status == discord.client.Status.online:
    
            names.append(member.name)

        print(names)
        await message.channel.send(names)

it returns the error 'Member has no attribute Status' despite the docs stating it does. It has also previously failed to identify discord.Status as a valid path despite the documentation stating it is. Any help would be appreciated. My bot has access to all permissions including all privileged gateway intents

ELBR
  • 13
  • 5
  • 1
    I believe it is a lowercase `s` https://discordpy.readthedocs.io/en/stable/api.html?highlight=member#discord.Member.status – MrDiamond Nov 23 '22 at 01:48
  • [The discord.Client docs](https://discordpy.readthedocs.io/en/latest/api.html?highlight=member#discord.Client.status) show that the attribute is `status` (lowercase) while the class is `Status` (capitalized). Does changing `member.Status` to `member.status` fix it? – Dash Nov 23 '22 at 01:49
  • changing the case now means that it is not erroring out but it is also now only returning an empty list even when online members are present – ELBR Nov 23 '22 at 01:57
  • After further testing, the bot seems to think everyone is offline, even when I am actively typing while the command goes through, and even setting the if to !=discord.client.Status.offline and setting my status to Do not disturb – ELBR Nov 23 '22 at 02:14
  • If you add a `print(member.status)` in the for loop, do all the members show up as offline? – Dash Nov 23 '22 at 02:37
  • try skipping the client, like this >> if member.status != discord.Status.offline ~~note the cases too – Sin Han Jinn Nov 23 '22 at 02:47
  • Printing the member status shows offline every time, and removing the client does not help. It seems like this is a bug on discord's end – ELBR Nov 23 '22 at 04:54

1 Answers1

0

You need member intents for this to function.

For more information on how to enable member intents, read the official documentation, or this answer that explains it quite clearly.

J Muzhen
  • 339
  • 1
  • 10