Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Не работает event.ref и event.ref_source #479

Open
d1n0z opened this issue Feb 2, 2023 · 1 comment
Open

Не работает event.ref и event.ref_source #479

d1n0z opened this issue Feb 2, 2023 · 1 comment

Comments

@d1n0z
Copy link

d1n0z commented Feb 2, 2023

Все версии самые последние
Код(вставил только то что имеет отношение к проблеме т.к. файл на 2000 строк, если чего-то не дописал то сорян):

class CreateLongPoll(VkLongPoll):
    def listen(self):
        while True:
            try:
                for event in self.check():
                    yield event
            except Exception as e:
                if str(e)[1] != '<':
                    print(e, end=" FROM MAIN.PY->MyLongPoll->listen\n")


class VkBot:
    def __init__(self):
        self.vk_session = vk_api.VkApi(token=vk_token)
        self.longpoll = CreateLongPoll(self.vk_session)
        self.vk = self.vk_session.get_api()
        self.event = None
        self.db = None

    def run(self):
        while True:
            for self.event in self.longpoll.listen():
                if self.event.type == VkEventType.MESSAGE_NEW and self.event.to_me and self.event.text:
                    try:
                        self.db = utils.getOrCreateUserById(self.event.user_id)
                        link = self.vk.utils.getShortLink(url=f"{cfg.linkongroup}?ref={self.db.vk_id}")
                        print(link['url'], link['short_url'])
                        print(self.event.ref, self.event.ref_source)
                    except:
                        traceback.print_exc()

if __name__ == "__main__":
    VkBot().run()
@d1n0z
Copy link
Author

d1n0z commented Feb 3, 2023

Разобрался. Нужно было искать атрибуты в ответе messages.getById(message_ids=[self.event.message_id])
У меня это выглядело следующим образом: self.vk.messages.getById(message_ids=[self.event.message_id], extended=1)['items'][0]['ref'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant