Reputation: 151
In supergroups, my bot gets a message every time a user joins the group (by registering a MessageHandler
with ~filters.private
filter), so I know who it is (from the new_chat_members
field) and I can kick it if it doesn't meet certain conditions (e.g. it has no username set).
However, if I put the bot in a channel, I don't get any message when a user joins it (or, at least, not by using a MessageHandler
). Is it possible to get the same behavior?
Thanks
Upvotes: 1
Views: 1887
Reputation: 7
Also you can use this code:
try:
member = await client.get_chat_member(CHANNEL_ID, chat_id)
if member.status not in [ChatMemberStatus.MEMBER,ChatMemberStatus.OWNER,ChatMemberStatus.ADMINISTRATOR]:
raise Exception("Not a member")
except:
keyboard = InlineKeyboardMarkup(
[[InlineKeyboardButton("Join in Channelš¢", url=CHANNEL_LINK)]]
)
await message.reply_text(
"You must join in channel to use the bot",
reply_markup=keyboard
)
return
Upvotes: 0
Reputation: 1131
In Groups and Supergroups this works by Telegram sending a Service Message, which you receive via filters.new_chat_members
, or in groups >= 10 000 members via a ChatMemberUpdated
event (ie no new Message).
Channels do not have such an update, and thus you cannot handle anything like this. Your best bet is to periodically query the Recent Actions by using app.get_chat_event_log()
, and filter for the returned list for the events you want.
Upvotes: 2