Answer the question
In order to leave comments, you need to log in
I am using node-telegram-bot-api library. Shows error ReferenceError: msg is not defined. What could be the problem?
At the initial stage, it immediately gives an error ReferenceError: msg is not defined. I looked at the office. documentation, the same const chatId = msg.chat.id is also used there, but for some reason it gives me an error
const TelegramApi = require('node-telegram-bot-api')
//Создаём переменную с токеном бота
const token = 'token'
const bot = new TelegramApi(token, {polling:true})
//Вытаскиваем поле текст для взаимодействия с ним
const text = msg.text;
//Вытаскиваем Id чата
const chatId = msg.chat.id;
bot.on('message', msg => {
bot.sendMessage(chatId, "Повторяю за тобой ${text}")
})
Answer the question
In order to leave comments, you need to log in
Yours msg
is only available in this part of the code:
bot.on('message', msg => {
bot.sendMessage(chatId, "Повторяю за тобой ${text}")
})
msg
is available inside these curly brackets msg => {}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question