这是我的代码:
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('Бот готов к работе!')

很可能您没有启用它
Intent,members这里列出了没有它机器人无法获取的内容并将其保存到缓存中,然后保存到数据库中(包括guild.members: https ://discordpy.readthedocs.io/en/stable /api.html#discord.Intents.members这是一般专业
Intent人士的:https ://discordpy.readthedocs.io/en/stable/intents.htmlIntent解决方案是在创建机器人时将 's 列表传递给它: