D
D
Danya Durov2021-08-01 21:46:41
Python
Danya Durov, 2021-08-01 21:46:41

How to write a bot for VK with conversation administration functions, namely kick, ban, mute and warning?

If in more detail about the teams, then after 3 previouss the participant receives a ban, a ban is a ban on finding a participant, and even if he is invited to a conversation, the bot will automatically exclude him, the ability to remove previous and bans, with a kick I think everything is clear and this is a ban on writing and so that the messages of the person in the mute are deleted.
I can’t find information anywhere on how to do such functions, please help
PS I would like to somehow restrict these commands from ordinary users (that is, these cmds are only for admins, and admins need to be assigned somehow)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
RINAMI, 2021-08-02
@RINAMI

The kick function is implemented very simply:

def kicker(id):
     vk.method("messages.removeChatUser", {'chat_id': id, 'user_id': mes.split(' ')[1]})
#Вызов
 if mes.split(' ')[0] == 'кик':
    mes = event.object.message['text']
    id = event.chat_id
    kicker(id)

About ban mute and warnings. To implement the ban function, you need a txt file, example:
Add the user ID to the txt file and check:
#Функция бана
def ban(id, user_id):
      vk.method("messages.removeChatUser", {'chat_id': id, 'user_id': user_id})
check = open('имя_файла', 'r')
recheck = check.read()
user_id = event.object.message['from_id']
if user_id in recheck :
       ban(id, user_id)

OR:
Create a check for the participant's entry into the conversation and a new function:
def banagain(id, rinvite_id)
      vk.method("messages.removeChatUser", {'chat_id': id, 'user_id': rinvite_id})
                try:
                    rin = event.message.action['type']
                    rinvite_id = event.message.action['member_id'] 
                except:
                    rinvite_id = -100
                    rin = ''
               if rin == 'chat_invite_user':
                  if rinvite_id in recheck:
                          banagain(id, rinvite_id)

The "prev" and mut methods are done almost exactly the same, but the time module is needed there, and the ban function itself can be implemented using the datetime module.
PS Using User Long Poll, you can make it so that after the ban the user is notified about it. You can also add a user to the banned list by interacting with files, you can read here

M
Michael, 2021-08-01
@lob4Noff

Start simple, namely create a bot , then gradually increase the functionality of the bot, test it in a private conversation.
The database can be made using csv, where user IDs, their statuses for the right to administer and send messages, and the number of warnings will be recorded.

S
Sicquze, 2021-08-02
@Sicquze

For a kick, only the messages.removeChatUser api method is needed.
For a ban, you should use a database in which you will write down the ID of the user you want to block. after that, every time a user comes in, check if he is in the table of blocked participants for a particular conversation, if so, then of course, exclude him using the same method as for the "kick" command
warnings, they need the same as a ban in the database , you need to write it in the VK ID table and immediately check the number of its warnings, and the number of warnings after which the participant is excluded.
mut also needs a database, where without it .. after each message, check if the participant is in the database in the mut table, then give him a warning and check again with the number of warnings in which the user is excluded.
If something is not clear, you can write to me in VK: vk.com/id559935246, or in telegram: @Sicquze_Dauphin

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question