Не работает добавление пользователя. Как это можно исправить?

При вводе команды /start выдает: UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:19003) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

const {Telegraf} = require('telegraf')
const Client = require('pg').Client


//db
class ClientCommander extends Client{
    constructor(config){
        super()
        this.config = {
            user: 'tb',
            password:'tb',
            host:'localhost',
            database: 'tb',
            port: 5432
            };
        try{
            this.client = new Client(this.config)
        } catch(err){
            console.log(err)
        }
    };
    addUser(user){
        try{
            this.client.connect()
            this.client.query(`insert into client(username, first_name, last_name, id) values (user['username'], user['first_name', user['last_name'], user['id']`) 
            //this.client.query(`insert into client(username, first_name, last_name, id) values (${user['username']}, ${user['first_name']}, ${user['last_name']}, ${user['id']})`)
            return true
        } catch(error){
            console.log(error)
        }
    }
    
}


const bot = new Telegraf('1626073078:AAEhQSNcWPNxMFjn8vltXKw4Oyk2qFtcs34')


const commander = new ClientCommander()

bot.start(async (ctx) => {
    console.log(ctx.from)
    ctx.reply('hi')
    await commander.addUser(ctx.from)
})
bot.help((ctx) => ctx.reply('Send me a sticker'))

bot.on('sticker', (ctx) => ctx.reply('?'))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))

bot.launch()

Ответы (0 шт):