https://api.vk.com/method/wall.post?owner_id=айди_владельца_поста&post_id=айди_поста&message=сообщение&access_token=TOKEN&v=V
data.json
и заполните его так{
"conversations": [
]
}
import vk_api
import json
vk_session = vk_api.VkApi(token='ТОКЕН')
vk = vk_session.get_api()
index = 1
while True:
try:
chat_info = vk.messages.getChat(chat_id=index)
data = json.load(open('data.json', encoding='utf-8'))
srt_info = {'title': f'{chat_info["title"]}', 'id': f'{chat_info["id"]}'}
data['conversations'].append(srt_info)
with open('data.json', 'w', encoding='utf-8') as file:
json.dump(data, file, indent=2, ensure_ascii=False)
file.close()
index += 1
except Exception as e:
print(repr(e))
if event.object.text == "Кик" or event.object.text == "кик":
vk.method("messages.removeChatUser", {
"chat_id": event.object.peer_id - 2000000000,
"member_id": event.obj.reply_message['from_id']})
longpoll = VkBotLongPoll(vk_session, idgrup)
def get_user(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
return vk.users.get(user_ids=domen)[0]["id"]
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
text = event.obj["message"]["text"].split()
if (len(text) == 2) and text[0] == "кик":
try:
vk.messages.removeChatUser(
chat_id=event.chat_id,
member_id=get_user(text[1])
)
except Exception as e:
vk.messages.send(
chat_id=event.chat_id,
message="Произошла ошибка.",
random_id=0
)
vk.messages.markAsUnreadConversation(peer_id=пир айди)
def get_name(uid: int) -> str:
data = vk.method("users.get", {"user_ids": uid})[0]
return "{} {}".format(data["first_name"], data["last_name"])
full_name = get_name(тут юзер айди)
messages.getChat
недоступен.messages.getConversationsById
def get_chat_title(chat):
return vk.method("messages.getConversationsById", {"peer_ids": chat})['items'][0]['chat_settings']['title']
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
print('Название беседы: ' + get_chat_title(event.obj.peer_id))
except Exception as e:
print(repr(e))
import vk_api
import random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="токен")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, айди группы)
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
if event.object.text == "пинг"
vk.method("messages.send",
{
"chat_id": event.object.peer_id - 2000000000,
"message": "понг",
"random_id": random.randint(1, 2147483647)
}
)