Как получить user id telegram bot
Перейти к содержимому

Как получить user id telegram bot

  • автор:

telegram.User¶

Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their id is equal.

  • id ( int ) – Unique identifier for this user or bot.
  • is_bot ( bool ) – True , if this user is a bot.
  • first_name ( str ) – User’s or bots first name.
  • last_name ( str , optional) – User’s or bots last name.
  • username ( str , optional) – User’s or bots username.
  • language_code ( str , optional) – IETF language tag of the user’s language.
  • can_join_groups ( str , optional) – True , if the bot can be invited to groups. Returned only in telegram.Bot.get_me requests.
  • can_read_all_group_messages ( str , optional) – True , if privacy mode is disabled for the bot. Returned only in telegram.Bot.get_me requests.
  • supports_inline_queries ( str , optional) – True , if the bot supports inline queries. Returned only in telegram.Bot.get_me requests.
  • bot ( telegram.Bot , optional) – The Bot to use for instance methods.

Unique identifier for this user or bot.

Type: int

is_bot ¶

True , if this user is a bot.

Type: bool

first_name ¶

User’s or bot’s first name.

Type: str

last_name ¶

Optional. User’s or bot’s last name.

Type: str

username ¶

Optional. User’s or bot’s username.

Type: str

language_code ¶

Optional. IETF language tag of the user’s language.

Type: str

can_join_groups ¶

Optional. True , if the bot can be invited to groups. Returned only in telegram.Bot.get_me requests.

Type: str

can_read_all_group_messages ¶

Optional. True , if privacy mode is disabled for the bot. Returned only in telegram.Bot.get_me requests.

Type: str

supports_inline_queries ¶

Optional. True , if the bot supports inline queries. Returned only in telegram.Bot.get_me requests.

Type: str

bot ¶

Optional. The Bot to use for instance methods.

Type: telegram.Bot

copy_message ( chat_id: Union[int, str], message_id: Union[str, int], caption: str = None, parse_mode: Union[DefaultValue[DVType], str, None] = None, caption_entities: Union[Tuple[MessageEntity, . ], List[MessageEntity]] = None, disable_notification: Union[DefaultValue[DVType], bool] = None, reply_to_message_id: Union[int, str] = None, allow_sending_without_reply: Union[DefaultValue[DVType], bool] = None, reply_markup: ReplyMarkup = None, timeout: Union[DefaultValue[DVType], float, None] = None, api_kwargs: Dict[str, Any] = None ) → MessageId¶

For the documentation of the arguments, please see telegram.Bot.copy_message() .

Returns: On success, instance representing the message posted.
Return type: telegram.Message

full_name ¶

Convenience property. The user’s first_name , followed by (if available) last_name .

Type: str

get_profile_photos ( offset: int = None, limit: int = 100, timeout: Union[DefaultValue[DVType], float, None] = None, api_kwargs: Dict[str, Any] = None ) → Optional[UserProfilePhotos]¶

For the documentation of the arguments, please see telegram.Bot.get_user_profile_photos() .

Convenience property. If username is available, returns a t.me link of the user.

Type: str

mention_html ( name: str = None ) → str¶

Parameters: name ( str ) – The name used as a link for the user. Defaults to full_name .
Returns: The inline mention for the user as HTML.
Return type: str

mention_markdown ( name: str = None ) → str¶

telegram.ParseMode.MARKDOWN is is a legacy mode, retained by Telegram for backward compatibility. You should use mention_markdown_v2() instead.

Parameters: name ( str ) – The name used as a link for the user. Defaults to full_name .
Returns: The inline mention for the user as markdown (version 1).
Return type: str

mention_markdown_v2 ( name: str = None ) → str¶

Parameters: name ( str ) – The name used as a link for the user. Defaults to full_name .
Returns: The inline mention for the user as markdown (version 2).
Return type: str

name ¶

Convenience property. If available, returns the user’s username prefixed with “@”. If username is not available, returns full_name .

Как узнать user_id в Telegram Bot по нажатию на кнопку(InlineKeyboard)?

Добрый день. У меня имеется в боте имеется inline keyboard, по нажатию на кнопки идет запись/чтение значений из базы данных.
Для чтения/записи данных мне нужно знать user_id пользователя.
Как взять user_id пользователя нажавшего кнопку?

Сейчас я беру user_id шаг назад и сохраняю его в переменную, но сейчас когда моим ботом пользуется уже несколько человек — бывает эту переменную кто-то перезаписывает и человеку выдаются данные из БД совсем другого юзера.
Вообщем, как взять user_id пользователя, который нажал inline кнопку?

GabrielRF/telegram-id

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

How to get an id to use on Telegram Messenger

The ultimate guide

This guide aims on bot developers. If you don’t develop Telegram Chatbots or don’t use Telegram CLI, this guide is not for you. Don’t expect to get phone numbers or to join groups by their id. Both are impossible.

Available on https://web.telegram.org/?legacy=1#/login (have to use the legacy Telegram web client)

Follow the steps displayed to log in the app.

It’s not possible to find the user ID using this method. So, the easiest way to do it is talking to @userinfobot. If you need to find somebody else’s ID, forward a message to the bot.

This bot is not mine! Use it on your own risk!

Click on the group you want and see the url displayed on your browser.

If it’s a public group, you can simply use it’s @name as an id.

If it’s private group, the url must be like:

If this is the case, then the group ID is -331054 . Always negative!

For private super groups the url must be like:

If this is the case, then the group ID whois be 1041843721 . But it’s important to know that super group IDs are always a 13 characters negative integer, so the correct ID is -1001041843721 .

Click on the channel you want and see the url displayed on your browser.

If it’s a public channel, the ID is @name of the channel.

If it’s a private channel then the url must be similar to:

If this is the case, then the channel ID would be 1018013852 . It’s important to know that channel’s IDs are always negative and 13 characters long! So add -100 to it, making the correct ID -1001018013852 .

The best way I found to get ids is using Telegram-CLI.

Install and run it. I recommend using bot mode -b , but it’s optional.

Run Telegram CLI :

Wait for it do load and then paste a bot token.

The output must be similar to this:

To get a user id, ask the user to send any message do the bot and observe it on Telegram CLI window.

The message must appear similar to this:

Then, on Telegram CLI , type:

Note that spaces are replaced by _ .

The output will be something like this:

There you go! The user id, on this example, is 9083329 .

Add the bot to the group. On Telegram CLI , a message will be printed.

Then, on Telegram CLI , type

Where test is the group’s name. Note that spaces are replaced by _ .

The output on Telegram CLI will be similar to:

So, the id for the example group is -148228539 .

Group ids are always a negative integer, so remember to add the — while using it on the Telegram API.

Finally, to get a channel id, add the bot as a channel administrator .

On Telegram CLI type:

where test is the channel’s name. The output must be like this:

Here is the trick. Every channel id is a 13 characters negative integer. So the id for this channel is -1001035716040 and not 1035716040 as printed.

You can use the app directly to generate a direct link to the message and it will contain the group/channel information.

It is not possible to get user ID from the app itself. Have to get it from a bot or CLI

Tap/click on the group you want and hold/right click on a message. Copy the message link.

If it’s a public group, you can simply use it’s @name as an id.

If it’s private group, it is not possible to get a link. Have to use CLI or Web method

For private super groups the link must be like:

If this is the case, then the group ID whois be 1041843721 . But it’s important to know that super group IDs are always a 13 characters negative integer, so the correct ID is -1001041843721 .

Tap/click on the channel you want and hold/right click on a message. Copy the message link.

If it’s a public channel, the ID is @name of the group.

If it’s a private channel then the url must be similar to:

If this is the case, then the channel ID would be 1018013852 . It’s important to know that channel’s IDs are always negative and 13 characters long! So add -100 to it, making the correct ID -1001018013852 .

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *