info_message = vk.messages.getById(message_ids=event.message_id)
invite = info_message['items'][0]['action']["type"]
invite_id = info_message['items'][0]['action']['member_id']
invite_get=vk.users.get(user_ids = (invite_id))
invite_get=invite_get[0]
first_name_invite_users=invite_get['first_name']
last_name_invite_users=invite_get['last_name']
["response"][0]["first_name"]
info = requests.get('https://api.vk.com/method/users.get', params={
'v': v,
'name_case': 'Nom',
'access_token': token,
'fields': 'photo_max_orig,counters'
}).json()
if "error" in info:
print("[red]Неправильный токен[/red]")
sys.exit()
first_name = info["response"][0]["first_name"]
last_name = info["response"][0]["last_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))
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(тут юзер айди)
def get_members(peer_id: int) -> list:
return vk.method("messages.getConversationMembers", {
"peer_id": peer_id
})["items"]
def get_admins(peer_id: int) -> list:
return [
i["member_id"] for i in get_members(peer_id)
if i.get("is_admin", False)
]
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.text == "какая-то команда":
if event.obj.from_id in get_admins(event.obj.peer_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
)