Rizqifeb
Rizqifeb

Reputation: 37

Telegram bot reply a chatid if user send command

I want to make a telegram bot that can reply/return a chatid if my users send the command /myid. What should I do?

Thanks in advance!

Upvotes: 2

Views: 536

Answers (1)

Beppe C
Beppe C

Reputation: 13883

Create a Command Handler which gets the chat_id from the payload, and send it back as response.

dp.add_handler(CommandHandler("myid", myid_command_handler))

def myid_command_handler(update, context):
 """Send back the chat_id"""
 chat_id = update.message.chat.id 
 update.message.reply_text('Here it is: ' + str(chat_id))

Upvotes: 1

Related Questions