I added bot to supergroup and created event that listen all messages.
bot.on('message', (msg) => {
const chatId = msg.chat.id;
bot.deleteMessage(chatId, msg.message_id);
});
How can I check if admin sent this message?
I use this workaround and seems to work.
bot.getChatMember(message.chat.id, message.from.id).then(function(data) {
if ((data.status == "creator") || (data.status == "administrator")){
// I'm admin or creator, so delete message
}
});
Where do you add that paragraph? It does not work for me
@DestroyerIV
bot.onText(/^\/ban/, function(message, match) {
bot.getChatMember(message.chat.id, message.from.id).then(function(data) {
if ((data.status == "creator") || (data.status == "administrator")){
bot.sendMessage(message.chat.id, "I'm admin!");
}else{
bot.sendMessage(message.chat.id, "I'm not admin");
}
});
});
Thanks bro, How can I join it to kickChatMember?
bot.onText(/^\/ban/, function(message) {
// Easy way is use this command via reply, so:
if (message.reply_to_message == undefined){
// Not used via reply
return;
}
var username = message.reply_to_message.from.username;
var userid = message.reply_to_message.from.id;
bot.getChatMember(message.chat.id, message.from.id).then(function(data) {
if ((data.status == "creator") || (data.status == "administrator")){
bot.kickChatMember(message.chat.id, userid).then(result => {
bot.sendMessage(message.chat.id, username + " has been banned!");
});
}
});
});
Thanks bro, good job. I am totally grateful
Thanks @sidelux !
Can this be closed then?
I think yes ;)
I have a question. Example I ban a person, then I use /unban to remove the ban. But if that person is inside the group and is not banned by using the command /unban the user receiver ban. I leave the code:
bot.onText(/^\/unban/, function(message) {
if (message.reply_to_message == undefined){
return;
}
var username = message.reply_to_message.from.username;
var userid = message.reply_to_message.from.id;
bot.getChatMember(message.chat.id, message.from.id).then(function(data) {
if ((data.status == "creator") || (data.status == "administrator")){
bot.unbanChatMember(message.chat.id, userid).then(result => {
bot.sendMessage(message.chat.id, message.from.first_name + " has been unbaned!");
});
}
});
});
Could you tell me how it can be solved? And if it is an insure?
Most helpful comment
I use this workaround and seems to work.