1

For my problem I ended up using the discom pip library, but if there is any other way to do what I want, I would be happy for the suggestions.

I want to find out what are the datetimes when a user joined a specific discord group. I managed to get all the IDs of the users from a group, but the documentation is so poor for this library, that I'm having trouble getting the username and datetime joined. I see, that it should be possible, but I can't figure it quite out.

The code I have for the IDs is:

import discum

bot = discum.Client(token="token")

def close_after_fetching(resp, guild_id):
    if bot.gateway.finishedMemberFetching(guild_id):
        lenmembersfetched = len(bot.gateway.session.guild(guild_id).members)
        print(str(lenmembersfetched)+' members fetched')
        bot.gateway.removeCommand({'function': close_after_fetching, 'params' :{'guild_id': guild_id}})
        bot.gateway.close()

def get_members(guild_id, channel_id):
    bot.gateway.fetchMembers(guild_id, channel_id, wait=1)
    bot.gateway.command({'function': close_after_fetching, 'params': {'guild_id': guild_id}})
    bot.gateway.run()
    bot.gateway.resetSession()
    return bot.gateway.session.guild(guild_id).members

members = get_members('guild_id', 'channel_id')
membersList = []

for memberID in members:
    membersList.append(memberID)
    print(memberID)

I end up with a list of all the member IDs, but I need more. Also, I have a suspicion, that the member list is not complete. Could that be true? I understand, that this library is not widely used, but any help (especially other solutions) would be much appreciated.

SOLUTION

I ended up using a discord bot to get the list. It is much easier and much more documented.I still used python, but with discord library. 'access_token' is my discord bot token and the answer is put into a .txt file, because it could be to large for discord message.

import discord
import os
from io import BytesIO
import datetime

access_token= os.environ["ACCESS_TOKEN"]

intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)


@client.event
async def on_ready():
  print('We have logged in as {0.user}'.format(client))

@client.event
async def on_message(message):
  if message.author == client.user:
    return

  if message.content.startswith('!members'):
    userrole = message.author.top_role.name
    if userrole == "Admin" or userrole == "Moderators":
      memberList = ""
      username = ''
      dateJoined = ''
      guilds = client.guilds
      for guild in guilds:
        members = guild.members
        for member in members:
          if member.bot == False:
            username = member.name
            dateJoined = member.joined_at.strftime("%d-%m-%Y %H:%M:%S")                  
            memberList = memberList + username + "," + dateJoined + "\n"

      as_bytes = map(str.encode, memberList)
      content = b"".join(as_bytes)
      await message.reply("Member List", file=discord.File(BytesIO(content), "members.txt"))         

client.run(access_token)
Oskars
  • 407
  • 4
  • 24

0 Answers0