B
B
BloodySamurai2021-10-23 14:55:36
Python
BloodySamurai, 2021-10-23 14:55:36

How to get user id through forwarded message?

In general, it is necessary that when replaying a forwarded message, the bot throws this message to the user, from whom he threw the initial one. Some kind of feedback

owner = #мойайдишник

@bot.message_handler(content_types=['text'])
def send_text(message):
  if message.chat.id == owner:
    if hasattr(message.reply_to_message, 'text'):
      bot.send_message(message.reply_to_message.from_user.id, message.text)
    else:
      pass
  else: 
    if hasattr(message, 'text'):
      x = message.chat.id 
      bot.forward_message(owner, message.chat.id, message.message_id)
      bot.send_message(x, 'Отправлено')


With this code, it writes that the bot cannot send a message to the bot, respectively, it considers the replicated message as its own. Moreover, if I answer my message, he will immediately send it to me. Help, how to fix it, so that he perceives the forwarded message not as his own, but for the corresponding user. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jerwright, 2021-10-23
@BloodySamurai

This code reacts to the replay of the forwarded message:

@bot.message_handler(content_types = ['text'])
def testing(message):
    if message.reply_to_message!=None and message.reply_to_message.forward_from!=None:
        bot.send_message(message.reply_to_message.forward_from.id, 'test')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question