I
I
Ivan Kuzmenko2021-03-21 18:50:38
Python
Ivan Kuzmenko, 2021-03-21 18:50:38

How to write all users to db when joining bot?

I know I'm dumb again.

@client.event
async def on_guild_join(guild):
  cur.execute(f"INSERT INTO prefix(guild, prefix) VALUES({guild.id}, '*')")
  con.commit()
  for member in client.get_all_members():
    user = str(member.id)
    guildid = str(member.guild.id)
    ult2 = f"{user}{guildid}"
    cur.execute(f"SELECT guild FROM users WHERE guild = '{ult2}'")
    if cur.fetchone() == None:
      cur.execute(f"INSERT INTO users(guild) VALUES({ult2})")
    else:
      print("No")
    con.commit()
    print("Yes")

Prints just for debugging
Tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-03-23
@shurshur

By default, the bot cannot get a list of users. Look towards Gateway Privileged Intents
https://discordpy.readthedocs.io/en/latest/intents.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question