Я нашел способ как это сделать, надеюсь это поможет и другим
# Запуск бота
print("Hello WOrld")
# Импорты
import asyncio
import vkbottle
from vkbottle.bot import Bot, Message
from vkbottle import Keyboard, KeyboardButtonColor, Text, OpenLink, Location, EMPTY_KEYBOARD, template_gen, TemplateElement
import aiosqlite
import config
# Создаем экземпляр бота
bot = Bot(config.VK_TOKEN)
# Создаем подключение к базе данных SQLite
async def create_connection():
connection = await aiosqlite.connect("users.db")
return connection
# Создаем таблицу пользователей
async def create_table(connection):
async with connection.cursor() as cursor:
await cursor.execute(
"""
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY,
user_id INTEGER,
username TEXT
)
"""
)
# Добавляем пользователя в базу данных
async def add_user(user_id: int, username: str, connection):
async with connection.cursor() as cursor:
await cursor.execute(
"""
INSERT INTO users (user_id, username)
VALUES (?, ?)
""",
(user_id, username)
)
await connection.commit()
# Обрабатываем команду /start
@bot.on.message(text="/start")
async def handle_start_command(message: Message):
# Получаем информацию о пользователе
user_id = message.from_id
username = f"{message.from_id.first_name} {message.from_id.last_name}"
# Создаем подключение к базе данных SQLite
async with create_connection() as connection:
# Создаем таблицу пользователей, если ее нет
await create_table(connection)
# Добавляем пользователя в базу данных
await add_user(user_id, username, connection)
# Отправляем приветственное сообщение
await message.answer("Привет! Вы были зарегистрированы в нашей базе данных.")
# Запускаем бота
async def main():
await bot.run_polling()
if __name__ == "__main__":
asyncio.run(main())```