E
E
Ekaterina2021-10-30 23:28:11
Python
Ekaterina, 2021-10-30 23:28:11

Why does the discord bot only see itself?

The discord bot needs to get the entire list of users and add it to the database (Mongo.db), but it only adds itself.
Although he sees others.
Intents included 617daaa2b4164973796199.jpeg

Source code:

intents = discord.Intents.all()
Intents.members = True
bot = commands.Bot(command_prefix= '-', intents = intents)
@bot.event
async def on_ready():    
    for guild in bot.guilds:
        for member in guild.members:
            print(member)
            post = {
                "_id": member.id,
                "balance": 0,
                "xp": 0,
                "lvl": 0
                }
            print(collection)
            if collection.find({"_id": member.id}) == None:
                collection.insert_one(post) 
                print('пользователь занесен в таблицу')


Console
me.wizzy#1111
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), 'bot'), 'keta')
Server Monitoring#8312
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), 'bot'), 'keta')
ToNi#2025
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), 'bot'), 'keta')
!                    #0001
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), <bot'), 'keta')
HaGle#2222
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), <b>'bot'), 'keta')</b>
Seba#5041
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), bot'), 'keta')
Хагис#4815
Collection(Database(MongoClient(host=['cluster0-shard-00-02.sbgr7.mongodb.net:27017', 'cluster0-shard-00-01.sbgr7.mongodb.net:27017', 'cluster0-shard-00-00.sbgr7.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-kvlg4c-shard-0', ssl=True), 'bot'), 'keta')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-10-31
@Vindicar

if collection.find({"_id": member.id}) == None:
That's suspicious, because the docs say find() returns a cursor. About None there is not a word.
So it may well be that an empty cursor is returned to you - i.e. not None.
Maybe you mean find_one() ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question