Node-telegram-bot-api: How to check if my bot is admin on a channel?

Created on 26 Oct 2018  路  5Comments  路  Source: yagop/node-telegram-bot-api

Question

I Want to check if my bot is admin on a channel or not without sending message.
I have the channel username.
I've searched a lot but I found nothing concrete !
Thanks !

Most helpful comment

You can try with that:

bot.getChatMember(message.chat.id, message.from.id).then(function (data) {
    if (data.status == "administrator") {     
        // is admin
    }
});

I don't know if it works with bots, but the only alternative that can works is to send a message and check for errors...

Thanks @sidelux , it's finally working, I just have to wait a bit.

All 5 comments

You can try with that:

bot.getChatMember(message.chat.id, message.from.id).then(function (data) {
    if (data.status == "administrator") {       
        // is admin
    }
});

I don't know if it works with bots, but the only alternative that can works is to send a message and check for errors...

Thanks @sidelux ! I'll try it !

@sidelux
capture d ecran 76

That is what I get !

Ok @HRNaudZ, so you can try with:

var isAdmin = 1;
bot.getChatMember(message.chat.id, message.from.id).then(function (data) {
    if (data.status != "administrator") 
        isAdmin = 0;
}).catch(function(e) {
    if (err.message.indexOf("CHAT_ADMIN_REQUIRED") != -1)
        isAdmin = 0;
});

You can try with that:

bot.getChatMember(message.chat.id, message.from.id).then(function (data) {
    if (data.status == "administrator") {     
        // is admin
    }
});

I don't know if it works with bots, but the only alternative that can works is to send a message and check for errors...

Thanks @sidelux , it's finally working, I just have to wait a bit.

Was this page helpful?
0 / 5 - 0 ratings