0

Вот мой код:

import discord
from discord.ext import commands

import sqlite3
from config import settings

client = commands.Bot(command_prefix = settings['PREFIX'])
client.remove_command('help')

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,
        cash BIGINT,
        rep INT,
        lvl INT
    )""")
    connection.commit()

    for guild in client.guilds:
        for member in guild.members:
            cursor.execute(f"SELECT id FROM users where id={member.id}")
            if cursor.fetchone() is None:
                cursor.execute(f"INSERT INTO users (name, id, cash, rep, lvl) VALUES ('{member}', {member.id}, 0, 0, 1)")
                connection.commit()
            else:
                pass

print('Бот готов к работе!')

Проблема заключается в том, что у меня в базу данных заносится только созданный бот. введите сюда описание изображения А другие участники не заносятся, хоть вроде должны. Помогите умоляю!!

1 ответ 1

0

Скорее всего у вас не включен Intent на members, вот тут указан список вещей, которые бот не может без него получить и сохранить в кеш, а далее в базу данных (включает в себя guild.members: https://discordpy.readthedocs.io/en/stable/api.html#discord.Intents.members

Здесь в целом, про Intent'ы: https://discordpy.readthedocs.io/en/stable/intents.html

Решение - при создании бота передать в него список Intent'ов:

intents = discord.Intents.default()
intents.members = True

client = commands.Bot(command_prefix = settings['PREFIX'], intents=intents)
1
  • Спасибо очень помогло!!! Не могли бы вы еще с кое чем помочь?
    – Timoha
    18 мая 2022 в 8:14

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.