A
A
Ampilda2021-09-14 22:29:55
Python
Ampilda, 2021-09-14 22:29:55

How to display the ID of the person to whom you replied to the VK bot?

For example, I want that when I reply to a person in a conversation and write !go to me, the bot would write something like: "ID: (ID of the person I replied to)" How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
old pinky, 2021-09-15
@Ampilda

from vkbottle import Bot
from vkbottle.bot import Message

bot = Bot(token='group_token')
bot.labeler.vbml_ignore_case = True

@bot.on.message(text=['айди', '!айди'])
async def user_id(message: Message):
    uid = message.reply_message.from_id
    await message.answer(f'Айди: {str(uid)}')

bot.run_forever()

W
wirflve, 2021-09-14
@wirflve

if event.obj.message["text"].lower() == '!айди':
    pid = event.obj.message["peer_id"]
    rid = event.obj.message['reply_message']['from_id']
    vk.messages.send(peer_id=pid, message=f'Айди: {rid}', random_id=0)

Reply to forwarded message :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question