Answer the question
In order to leave comments, you need to log in
How to make a kick at the mention of VK?
Liba - vkbottle
There is already a kick on the response to the message, I want to do it by mention and link
Script of the kick to reply to the message:
@bot.on.chat_message(lower=True, text=['кик', 'бан', 'ban', 'kick'])
@swear(VKError, exception_handler=exc_kick)
async def kick(message: Message):
members = await message.api.messages.get_conversation_members(
peer_id=message.peer_id
)
admins = [member.member_id for member in members.items if member.is_admin]
if message.from_id not in admins:
await message('ты не одмен беседы.')
else:
txt = message.reply_message.text
await bot.api.messages.remove_chat_user(message.peer_id - 2000000000, message.reply_message.from_id)
return "Пользователь успешно исключён"
Answer the question
In order to leave comments, you need to log in
The mention comes in this form [id12345|Вася Пупкин]
. You just need to remove everything unnecessary and pass the id to the user exclusion method
def get_user_id(pattern: str) -> int:
if "[id" in pattern:
return int(pattern.split("|")[0].replace("[id", ""))
def get_user_id(pattern: str) -> int:
if "vk.com/" in pattern:
domen = pattern.split("/")[-1]
return vk.method("users.get", {"user_ids": domen})[0]["id"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question