Answer the question
In order to leave comments, you need to log in
How to make a vkbottle mailing list by time?
It is necessary to send out a timer: I use the schedule library for this .
As soon as the time reaches the desired time, an error appears in the console:
NameError: name 'message' is not defined
Here is the code:
vk_session = VkApi(token=tok)
vk = vk_session.get_api()
bot = Bot(token=tok)
def main_loop():
thread = Thread(target=do_schedule)
thread.start()
def NAME():
vk.messages.send(
message ="TEXT",
chat_id = message.chat_id,# Если нужно выслать в чат
#peer_id = user_id, # Если нужно выслать в ЛС
random_id=0)
def do_schedule():
schedule.every().day.at("21:29").do(NAME)
while True:
schedule.run_pending()
time.sleep(1)
if __name__ == '__main__':
main_loop()
bot.run_forever()
Answer the question
In order to leave comments, you need to log in
Vinogradov ,
from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
group_id = "*****"
TOKEN = "*****"
vk_session = VkApi(token=TOKEN)
longpoll = VkBotLongPoll(vk_session, group_id)
vk = vk_session.get_api()
def main():
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat:
chat_id = event.chat_id
print(chat_id)
if __name__ == '__main__':
main()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question