Answer the question
In order to leave comments, you need to log in
How to implement check for admin in a conversation?
This script should check the user who wrote the command for the admin or the creator in the conversation, BUT when I write the command, the script does not react in any way, what should I do? Wrote on vk_api using longpoll
if event.type == VkBotEventType.MESSAGE_NEW and event.obj.text.lower() == "kick" or event.obj.text.lower() == "кик":
buf=[]
for element in vk.messages.getConversationMembers(peer_id=event.obj.peer_id,fields='items')['items']:
if element.get('is_admin') and element['is_admin'] is True:
buf.append(element['member_id'])
if event.obj.from_id in buf:
print('Выполняем код')
vk.messages.removeChatUser(chat_id=event.chat_id, user_id=event.obj.fwd_messages[0]['from_id'])
import vk_api # Библиотека VK
from datetime import datetime # Библиотека DateTime
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType # Библиотека VK LongPool
# Настройки
token = "токен" # Личный access_token сообщества (Желателен полный доступ)
group_id = "id" # ID сообщества
server = "@id" # Владелец кода
longpool_sleep = "0.5" # Задержка проверки сообщений, зависит от нагрузки на сервер (Рекомендуется значение от 0.1 до 10)
# VK LongPool
vk_session = vk_api.VkApi(token = token) # Обработка access_token
longpoll = VkBotLongPoll(vk_session, group_id) # Данные для работы в сообществе
vk = vk_session.get_api() # Работа с VK API
# Info
version = "release 7.0" # Версия бота
api_version = "5.92" # Версия VK API
system = "LongPoll" # LongPoll или CallBack
language = "Python 3.7.2" # Язык и версия языка
# Time
servertime = str(datetime.strftime(datetime.now(), "%H:%M")) # Время сервера
# Сообщения
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.obj.text.lower() == "test" or event.obj.text.lower() == "тест":
vk.messages.send(peer_id = event.obj.peer_id, random_id = 0, message = "Tested!")
vk.messages.send(peer_id = event.obj.peer_id, random_id = 0, message = "Отправьте команду help для получения списка комманд бота")
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question