Правильный способ отображения приветствия в телеграмме - PullRequest
0 голосов
/ 12 апреля 2020

Вопрос здесь относительно показа Приветственного сообщения в чате:


bot.on('new_chat_members', (ctx) => {

console.log(ctx.message.new_chat_members) // console log works well giving out the right array // the next console log doesn't work and makes me cofused

console.log(ctx.message.new_chat_members.username) // log is undefined

// As far as I understood that line should work... but it's not.

bot.telegram.sendMessage(ctx.chat.id, "Welcome to the official Chat @" + ctx.message.new_chat_members.username); })```

1 Ответ

0 голосов
/ 12 апреля 2020

Telegram передает новые члены внутри массива, независимо от того, является ли он одним или несколькими.

ctx.message.new_chat_members

Это массив, вы должны перебирать каждого пользователя в массиве и затем регистрировать их имя пользователя.

так:

for (const user of ctx.message.new_chat_members) {
    console.log(user.username)
}
...