T
T
TheMurkovich22020-11-03 02:13:12
Python
TheMurkovich2, 2020-11-03 02:13:12

How to add all users to Mongo?

I have a Python discord bot, I connected it to MongoBD, but the question arose: how to add all servers and all users to the database?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2020-11-03
@TheMurkovich2

from motor.motor_asyncio import AsyncIOMotorClient  # https://pypi.org/project/motor/

client = AsyncIOMotorClient(host="localhost", port=27017)
db = client["mydatabasename"]
for user in bot.users:
    await db.users.insert_one(
        {
            "id": user.id,
            "name": user.name,
            "discrim": user.discriminator,
            "bot": user.bot,
            "system": user.system,
        }
    )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question