pengrad / java-telegram-bot-api

Telegram Bot API for Java
https://core.telegram.org/bots
Apache License 2.0
1.81k stars 373 forks source link

Getting ID through arguments #363

Closed scar-day closed 2 months ago

scar-day commented 9 months ago

Hello, is there any function that gives user ID through arguments (for example I write like this: /id @ and it will give ID)

mircoianese commented 9 months ago

Hello, if you mean that you need to get the ID of users without using BOTs API then you can use unofficial apps (like Plus Messenger on Android or Nicegram on iOS). You will be able to see the User ID in the User profile. If you are looking instead to create a Telegram BOT that will send you the of users that starts it, you can do something like this:

if (update.message() != null && update.message().text() != null && update.message.text().equals("/start")) {
SendMessage msg = new SendMessage(YOUR_TELEGRAM_ID, "User started the bot: " + update.message().from().id());
bot.execute(msg);
}