Node-telegram-bot-api: Understand getChatMember

Created on 16 Sep 2018  路  5Comments  路  Source: yagop/node-telegram-bot-api

Im traying to check if a user is in a chat, i just found this fucntion, but i dont know how to work with it.

I try to open in with a log but there is no usefull info, also i try an If/else, but when a user was not the chat it throws an error.

Can anyone help me? Or maybe help me with a diferent function to do that?.
Thanks

question

Most helpful comment

Use this:

bot.getChatMember(chatId,userId).then(() => { console.log("Exist"); }).catch((e) => { if(e.response.body.error_code == 400){ console.log("Not exist"); } } );

Thanks man, it works.

All 5 comments

Can you please elaborate the problem and copy the snippet please.

I try to know if a userId is in a chat. So the function i have found is getChatMember, but im not sure how to work with it.
I have tryed all this thigs:
console.log(bot.getChatMember(chatId,userId)) The console shows nothing relevant to know if the user is in the chat or not.

if(bot.getChatMember(chatId,userId)){ console.log('Exist') }else{ console.log('Not exists') } It always say exist, but when the user is not in the chat it also shows an error.

Use this:

bot.getChatMember(chatId,userId).then(() => { console.log("Exist"); }).catch((e) => { if(e.response.body.error_code == 400){ console.log("Not exist"); } } );

Use this:

bot.getChatMember(chatId,userId).then(() => { console.log("Exist"); }).catch((e) => { if(e.response.body.error_code == 400){ console.log("Not exist"); } } );

Thanks man, it works.

Closing since question is answered. The method returns a promise which has to be resolved.

Was this page helpful?
0 / 5 - 0 ratings