import vk_api
import json
from vk_api.utils import get_random_id
bd = open("bd.json", "r")
data = json.loads(bd.read())
data["id"]
def main():
vk_session = vk_api.VkApi(token='токен')
vk = vk_session.get_api()
for id in bd:
vk.messages.send(
user_id=id,
random_id=get_random_id(),
message="что"
)
if __name__ == '__main__':
main()
{"id": [мой айди]}
from vk_api import VkApi
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
import pytz
import time
from datetime import datetime
from vk_api.utils import get_random_id
tz_moscow = pytz.timezone('Europe/Moscow')
time_moscow = datetime.now(tz_moscow)
print("")
print("====================================")
print("Бот работает!")
print("")
print("The Bot by R_u_B_i_k")
print("====================================")
send = " отправлено!"
time.sleep(0.2)
def main() -> None:
vk_session = VkApi(token='токен')
long_poll = VkBotLongPoll(vk_session, 'айди группы')
vk = vk_session.get_api()
def get_name(uid: int) -> str:
data = vk.method("users.get", {"user_ids": uid})[0]
return "{} {}".format(data["first_name"], data["last_name"])
fullname = get_name(1)
for event in long_poll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
time.sleep(0.2)
peer_id = event.obj['peer_id']
message = event.obj['text'].lower()
if message == 'ку':
vk.messages.send(
peer_id=peer_id,
message='Здравствуй ' + fullname,
random_id=get_random_id(),
)
print('[INFO]', time.strftime("%H:%M:%S"), 'отправлен ответ: приветствие')
if __name__ == '__main__':
main()