Comments (34)
If your message
handler comes before new_chat_members
, then try swapping them.
That is:
const TelegramBot = require('node-telegram-bot-api');
const token = '<bot_token>';
const bot = new TelegramBot(token, { polling: true });
bot.on('new_chat_members', (msg) => {
console.log(msg)
});
bot.on('message', (msg) => {
console.log(msg)
});
from node-telegram-bot-api.
Hello.
Are administrator rights granted to the bot?
from node-telegram-bot-api.
Without administrator rights, it does not track this event.
from node-telegram-bot-api.
Hi @VDS13 😊🙏 thanks for your answer.
My bot is already Admin in the group where I added it.
You mean I have to set something in botfather?
And do you know why it works perfectly for test bots created under my account and joining the group, but not with other users?
from node-telegram-bot-api.
Hello. Are administrator rights granted to the bot?
Yes they already are
from node-telegram-bot-api.
Is the group public or private?
from node-telegram-bot-api.
@VDS13
Hey Dmitry, it is public
from node-telegram-bot-api.
Strange.
Let's summarize: a bot with administrator rights, a public group, not a supergroup, new_chat_members
works on your bots, but not on users?
from node-telegram-bot-api.
yes exactly ! i agree it is weird :)
here is the group: https://t.me/Souffles_Magiques
from node-telegram-bot-api.
Show a piece of code from the beginning to the new_chat_members
event handler.
from node-telegram-bot-api.
bot.on('new_chat_members', (msg) => {
console.log(msg)
}
});
nothing is coming. I want channel id through my bot like https://t.me/username_to_id_bot bot is doing.
from node-telegram-bot-api.
There are no others in the code before this handler (let's say bot.on('message', ...)
)?
from node-telegram-bot-api.
const TelegramBot = require('node-telegram-bot-api');
const token = '<bot_token>';
const bot = new TelegramBot(token, { polling: true });
bot.on('message', (msg) => {
console.log(msg)
}
});
I am trying to get channel_id when my bot joins any channel. how can I do it? can you give me any solution
from node-telegram-bot-api.
Still not working, I am getting message when i send to bot, but while adding bot to any channel I am not getting any channel_id, new-chat_members not working. This is working for groups but not channels.
from node-telegram-bot-api.
Hi @VDS13
Here is a test code using what I use:
import TelegramBot from 'node-telegram-bot-api';
// Replace 'YOUR_BOT_TOKEN' with your actual bot token
const bot = new TelegramBot('xxxxxxxxxxxxxxx', { polling: true });
// Event handler for new chat members
bot.on('new_chat_members', (msg) => {
console.log('New user event triggered');
console.log('New chat members:', msg.new_chat_members);
// Process new members
processNewMembers(msg.new_chat_members);
});
// Function to process new members
const processNewMembers = (newMembers) => {
newMembers.forEach((member) => {
console.log('New member:', member);
// Perform any additional processing here
});
};
// Event handler for messages
bot.on('message', (msg) => {
console.log('Received message:', msg.text);
});
// Start the bot
console.log('Bot is running...');
from node-telegram-bot-api.
Obviously I'm not the only one with this problem. Telegram maybe changed something and your event handler has to be updated ?
from node-telegram-bot-api.
@dev-anshu
for me adding a test bot created with botfather is working ! Event is triggerd. But any other bot or real user not.
from node-telegram-bot-api.
that's weird, anyway you can try go to botFather, use /mybots -> select your bot -> Gruop Privacy -> Turn off
from node-telegram-bot-api.
Hi @Sp3rick
Thanks for your help.
I did it but it did not work.
@VDS13 Do you, or anyone reading this, succeed with the code i provided in a group of yours ?
Are you sure events from library are up to date?
from node-telegram-bot-api.
Is there any dev knowing if the code is still working ?
@yagop @GochoMugo @kamikazechaser @danielperez9430 ?
Cheeers
from node-telegram-bot-api.
Source: https://core.telegram.org/bots/api-changelog#april-26-2021
from node-telegram-bot-api.
So now, use "chat_member" for know if user join or left.
This warning is from 3 years ago, so maybe now is deprecated for normal users.
from node-telegram-bot-api.
So now, use "chat_member" for know if user join or left.
This warning is from 3 years ago, so maybe now is deprecated for normal users.
You can try the following, it works for me. It detects both input and output in groups.
let TelegramBot = require('node-telegram-bot-api');
let bot = new TelegramBot('YOUR_TOKEN', { "polling": true })
bot.on('chat_member', (memberStatus) => {
console.log(memberStatus)
})
This code would return something similar to the following image
from node-telegram-bot-api.
Thanks for your answers @danielperez9430 and @IscoV 😊👍
I just used your code @IscoV but bot does not see nor any user nor any bot now.
When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes?
Cheers
Ps: node-telegram-bot version is 0.64.0
from node-telegram-bot-api.
I used:
let TelegramBot = require ('node-telegram-bot-api');
// Replace 'YOUR_BOT_TOKEN' with your actual bot token
let bot = new TelegramBot('XXXX', { polling: true });
// Event handler for new chat members
bot.on('chat_member', (memberStatus) => {
console.log('User event triggered');
//console.log(memberStatus);
let {chat, from, date, old_chat_member, new_chat_member } = memberStatus;
console.log("Chat: ", chat);
console.log("From: ", from);
console.log("Date: ", date);
console.log("Old Member: ", old_chat_member);
console.log("New Member: ", new_chat_member);
});
// Start the bot
console.log('Bot is running...');
from node-telegram-bot-api.
Thanks for your answers @danielperez9430 and @IscoV 😊👍
I just used your code @IscoV but bot does not see nor any user nor any bot now.When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes?
CheersPs: node-telegram-bot version is 0.64.0
At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.
from node-telegram-bot-api.
Thanks for your answers @danielperez9430 and @IscoV 😊👍
I just used your code @IscoV but bot does not see nor any user nor any bot now.
When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes?
Cheers
Ps: node-telegram-bot version is 0.64.0At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.
@IscoV Yes yes, I'm talking about this. I added a bot and a user joined for testing. Nothing shows.
Have you tested it now on your group ?
from node-telegram-bot-api.
Thanks for your answers @danielperez9430 and @IscoV 😊👍
I just used your code @IscoV but bot does not see nor any user nor any bot now.
When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes?
Cheers
Ps: node-telegram-bot version is 0.64.0At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.
@IscoV Yes yes, I'm talking about this. I added a bit and a user joined for testing. Nothing shows.
Have you tested it now on your group ?
I tested it before sending it. Else, try to enable the update manually.
Paste the following URL in your browser and replace the YOUR_BOT_TOKEN
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates?allowed_updates=["update_id","message","edited_message","channel_post","edited_channel_post","inline_query","chosen_inline_result","callback_query","shipping_query","pre_checkout_query","poll","poll_answer","my_chat_member","chat_member"]
from node-telegram-bot-api.
'new_chat_members' event sometimes works, sometimes it doesn't
from node-telegram-bot-api.
'new_chat_members' event sometimes works, sometimes it doesn't
You too?
Is there any dev who is planning to fix this?
Do you know a library that works for this? Better not lose more time if it seems so complex to have a fix for node telegram bot .
from node-telegram-bot-api.
Thanks for your answers @danielperez9430 and @IscoV 😊👍
I just used your code @IscoV but bot does not see nor any user nor any bot now.
When have you tested those lines of code? In a group? Why would my bot not see anything and yours yes?
Cheers
Ps: node-telegram-bot version is 0.64.0At the time of execution, it should not show anything. It should only show the information when adding or joining a user/bot to the group.
@IscoV Yes yes, I'm talking about this. I added a bit and a user joined for testing. Nothing shows.
Have you tested it now on your group ?I tested it before sending it. Else, try to enable the update manually.
Paste the following URL in your browser and replace the YOUR_BOT_TOKEN
https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates?allowed_updates=["update_id","message","edited_message","channel_post","edited_channel_post","inline_query","chosen_inline_result","callback_query","shipping_query","pre_checkout_query","poll","poll_answer","my_chat_member","chat_member"]
Thanks but I don't understand what you mean?
I just have to do this one time and then new members event will work when my script is launched? Thanks a lot 🙏
from node-telegram-bot-api.
Seems there is no solution till now.
Are the main devs working on fixing this?
I'll start using telegraf in the meantime, and if it works I'll share it to you all. Better use something that works and well supported till fixes are coming.
Cheers
from node-telegram-bot-api.
hey all, I confirm there is something weird regarding the messages of the users who join in a group. Until two days ago the messages were showed, now they aren't. The result is that the following function to ban users who join the group and forward a message doesn't work:
def is_new_group_member(chat_id, user_id):
return user_id in new_group_members.get(chat_id, [])
async def handle_new_user(update: Update, context: CallbackContext):
chat_id = update.message.chat.id
new_users = update.message.new_chat_members
for user in new_users:
if user.id not in new_group_members.get(chat_id, []):
if chat_id not in new_group_members:
new_group_members[chat_id] = []
new_group_members[chat_id].append(user.id)
async def handle_forwarded_message(update: Update, context: CallbackContext) -> bool:
user_id = update.message.from_user.id
chat_id = update.message.chat.id
message_id = update.message.message_id
if update.message.forward_date and is_new_group_member(chat_id, user_id):
try:
await context.bot.ban_chat_member(chat_id, user_id)
await context.bot.delete_message(chat_id, message_id)
await context.bot.send_message(chat_id, "User has been banned")
await context.bot.send_message(user_id, "If you think it's an error")
# Remove the user from the new members list to prevent repeated actions
new_group_members[chat_id].remove(user_id)
return True
except Exception as e:
print(f"Failed to ban user or delete message: {e}")
return False
return False
Does anyone know how to solve and make this function working properly always?
from node-telegram-bot-api.
Solution here: #1139 (comment)
from node-telegram-bot-api.
Related Issues (20)
- how to create sticker with pack, i'm new with this library so i got many error while trying
- sendMediaGroup - InputMediaDocument HOT 2
- question how to save photos by reply HOT 1
- multiple upload file HOT 1
- bot.on('message', ...) works unexpected
- Occasionally not receiving message update
- Listening for a reply to an image with the '/isimage' command, replying with a message saying 'this is an image' HOT 1
- Deleting old message IDs in Telegram
- function createInvoiceLink not exist HOT 1
- Add to sendInvoice start_parameter HOT 2
- Pre-Checkout Timeout Error while making a Payment HOT 5
- The editMessageMedia method is working a bit wrong
- The 'Update' object sometimes does not have an attribute 'reply_to_message' in private messages
- Webhook setup via URL returns blank
- Business Mode HOT 6
- please help me i got this error HOT 1
- Bot replys to user no problem, but when i want it to send announchment to channel or group. nothing happens
- I have problem. I have more than 1,500 users, and the bot checks the site if products are available and sends for All the users if they are available. I set that it checks the site every 50 seconds so that the users can get the notification before the stock runs out, but I faced a problem, which is that it is very late. In the transmitter
- Bot occasionally doesn't receive update
- I always get 401 unauthorized error when use test bot HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-telegram-bot-api.