N
N
nesterso2022-02-18 14:47:58
Python
nesterso, 2022-02-18 14:47:58

Why is the bot texting instead of chatting?

import vk_api
import json
from vk_api.longpoll import VkLongPoll, VkEventType
import time
import random

bot_id = 624759656 # айди вашего бота
token = "tok"
vk = vk_api.VkApi(token=token)
longpoll = VkLongPoll(vk)


def kick_user(user_id):
    vk.method("messages.removeChatUser",{'chat_id' : 59, 'peer_id' : 2000000000 + 59,'user_id' : id,'member_id' : id})
# if user_id == admin_id and mess_user = 'kick':

def mafia_zam_leader(user_id):
    vk.method('messages.addChatUser', {'chat_id' : 62, 'user_id' : id,'member_id' : id})
def mafia_zam_kurilka(user_id):
    vk.method('messages.addChatUser', {'chat_id' : 67, 'user_id' : id,'member_id' : id})
def mafia_zam_zabiv(user_id):
    vk.method('messages.addChatUser', {'chat_id' : 63, 'user_id' : id,'member_id' : id})

def sender_leader_maf(id,text):
    vk.method("messages.send", {'user_id' : id, 'message' : text, 'random_id' : 0, 'peer_id' : 2000000000 + 62, 'chat_id' : 62})
def sender_kurilka_maf(id,text):
    vk.method("messages.send", {'user_id' : id, 'message' : text, 'random_id' : 0, 'peer_id' : 2000000000 + 67, 'chat_id' : 67})
def sender_zabiv_maf(id,text):
    vk.method("messages.send", {'user_id' : id, 'message' : text, 'random_id' : 0, 'peer_id' : 2000000000 + 63, 'chat_id' : 63})

# Основной цикл

for event in longpoll.listen():


        # Если пришло новое сообщение
    if event.type == VkEventType.MESSAGE_NEW:

            # Если оно имеет метку для меня( то есть бота)
        if event.to_me:

                # Сообщение от пользователя
                request = event.text
        if event.from_chat:
                msg = event.text.lower()
                id = event.user_id
                invite_id = event.user_id

                # Каменная логика ответа
        if request == 'Заместитель мафии' and id != bot_id:
                    kick_user(event.user_id)
                    mafia_zam_zabiv(event.user_id)
                    sender_zabiv_maf(event.user_id, f'Новый заместитель мафий @{invite_id}, прочитай закреп')

The bot writes these messages to me in PM, and not in a conversation. What is the problem?. If you specified a conversation ID

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Muntyan, 2022-02-18
@nesterso

in your function

def sender_zabiv_maf(id,text):
    vk.method("messages.send", {'user_id' : id, 'message' : text, 'random_id' : 0, 'peer_id' : 2000000000 + 63, 'chat_id' : 63})

'user_id' is specified, that is, you send a PM to the user, to send a message to the chat, you need to pass the id to 'chat_id'.
Link to documentation: *TYK*

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question