Answer the question
In order to leave comments, you need to log in
Question to the removeChatUser method, how to do it right?
I don't understand what is wrong, can anyone help me?
if event.object.text.lower() == 'text':
user = vk.method("users.get", {"user_ids": event.object.from_id})
kick = user[0]['id']
vk.method("messages.removeChatUser", {"peer_id": event.object.peer_id, "user_id": kick})
Answer the question
In order to leave comments, you need to log in
by reply to a message
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
)
Where did peer_id come from?
https://vk.com/dev/messages.removeChatUser
You read the documentation correctly. You must pass the chat_id parameter, not the peer_id. Also, why bother and get a person's ID through user.get? Just put in user_id: event.object.from_id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question