Hey this is my following code and it works, but I only get the users with whom I chatted(in private chat) once.
@client.command()
async def hi(ctx):
with
You might need to call fetch_members to update the clients internal cache from the Discord API:
@client.command()
async def hi(ctx):
with open('users.txt','w') as f:
async for member in ctx.guild.fetch_members(limit=None):
print("{},{}".format(member,member.id), file=f,)
print("done")
Do you have Intents enabled, if not, enable them and try.