Answer the question
In order to leave comments, you need to log in
How to add all server members to the database?
Hello! I am writing my little economic bot for my server.
import sqlite3
from discord.ext import commands
from config import settings
client = commands.Bot(command_prefix=settings['PREFIX'])
connection = sqlite3.connect('server.db')
cursor = connection.cursor()
@client.event
async def on_ready():
cursor.execute("""CREATE TABLE IF NOT EXISTS users (
name TEXT,
id INT,
money BIGINT,
rep INT,
lvl INT
)""")
for guild in client.guilds:
for member in guild.members:
if cursor.execute(f"SELECT id FROM users WHERE id = {member.id}").fetchone() is None:
cursor.execute(f"INSERT INTO users VALUES ('{member}', {member.id}, 0, 0, 1)")
else:
pass
connection.commit()
print(f'{client.user} - бот успешно запущен')
client.run(settings['TOKEN'])
Answer the question
In order to leave comments, you need to log in
open developer portal => select your app => go to bot tab => scroll down to Privileged Gateway Intents => enable PRESENCE INTENT and SERVER MEMBERS INTENT => click Save Changes and restart your bot.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question