Answer the question
In order to leave comments, you need to log in
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
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)
#Функция бана
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)
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)
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.
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 questionAsk a Question
731 491 924 answers to any question