Answer the question
In order to leave comments, you need to log in
How to limit commands?
Prompt good people how to make a command Restriction on commands.
I want the 'kick' command to work only for admins and not for normal members to use it.
And if possible, how can I make the "call" command work with the mention of the participant in the conversation, that is, through: @
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
from vk_api.utils import get_random_id
def write_message(sender, message):
"""Функция отправки сообщения"""
authorize.method('messages.send', {'chat_id': sender, 'message': message,
'random_id': get_random_id()
})
def get_name(from_id):
"""Функция упоминание участника беседы"""
if from_id > 0:
sender_info = getting_api.users.get(user_ids=from_id)[0]
full_name = sender_info.get('first_name') + ' ' + sender_info['last_name']
else:
return '174105461'
def get_chat_member(sender, group_id, user_name_search):
"""Функция - позвать участника беседы"""
members = getting_api.messages.getConversationMembers(peer_id=2000000000 + sender, group_id=group_id)['profiles']
for i in range(len(members)):
if members[i]['first_name'].lower() == user_name_search:
user_id = members[i]['id']
full_name = members[i]['first_name'] + ' ' + members[i]['last_name']
appeal = '@id' + str(user_id) + ' (' + full_name + ')'
return appeal
token = 'токен'
authorize = vk_api.VkApi(token=token)
longpoll = VkBotLongPoll(authorize, group_id=000000)
getting_api = authorize.get_api()
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 getting_api.users.get(user_ids=domen)[0]["id"]
print('Бот запущен!')
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW and event.from_chat and event.message.get('text') != '':
received_message = event.message.get('text').lower()
sender = event.chat_id
from_id = event.message.get('from_id')
name = get_name(from_id)
text = event.obj["message"]["text"].split()
if (len(text) == 2) and text[0] == "!кик":
try:
getting_api.messages.removeChatUser(
chat_id=event.chat_id,
member_id=get_user(text[1])
)
except Exception as e:
getting_api.messages.send(
chat_id=event.chat_id,
message="⚠ Ошибочка",
random_id=0
)
if received_message == '!лейла':
write_message(sender, 'Соска')
elif received_message == 'спокойной ночи':
write_message(sender, 'Добрых снова, зайка!' + ', ' + name)
elif received_message == '!общий сбор':
write_message(sender, 'Внимание олухи!' ' ' + name + ' ' 'Объявляет общий сбор! @all ')
elif received_message == '!созвать онлайн':
write_message(sender, 'Внимание лапиндосы!' ', ' + name + 'Говорит: не молчите! @online ')
elif received_message == '!кофе':
write_message(sender, 'Кофе и кофе, че бубнить то... ')
elif received_message == '!инсайдер':
write_message(sender, 'Самый крутой чел на планете ')
elif received_message == '!эмили':
write_message(sender, 'Солнышко ')
elif received_message == '!виктор':
write_message(sender, 'Злобный пёс ')
elif received_message[0:6] == 'позови':
user_name_search = received_message[7:]
chat_member = get_chat_member(sender, групп id, user_name_search)
if chat_member is None:
write_message(sender, 'Данный пользователь отсуствует в беседе')
else:
write_message(sender, chat_member + ', вас вызывают')
elif received_message == 'люц':
write_message(sender, "✅ demon of darkness here!")
elif received_message == 'помощь':
write_message(sender, ' Полный список команд можно почитать тут: \n/bZeII3')
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