import vk_api
from vk_api.longpoll import VkLongPoll, VkEventType
vk_session = vk_api.VkApi(token='токен')
longpoll = VkLongPoll(vk_session)
vk = vk_session.get_api()
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.messages.send( **locals(), random_id=0)
while True:
try:
for event in longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.text == "привет":
send_msg(event.peer_id, "Привет")
except Exception as e:
print(repr(e))
if 'action' in event.raw['object']:
if 'chat_invite_user' or 'chat_invite_user_by_link' in event.raw['object']['action']['type']:
user_id = event.raw['object']['action']['member_id']
text_1 = event.obj['text'].split(' ', maxsplit=1)
if text_1[0] == "Репорт":
vk.method("messages.send",
{
"user_id": тут айди админа,
"message": "Новый репорт: " + f'{text_1[1]}',
"random_id": 0
})
VkLongPoll, VkEventType
VkBotLongPoll, VkBotEventType
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="ТОКЕН")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, АЙДИ ГРУППЫ)
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.method("messages.send", {**locals(), "random_id": 0})
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id: #Для беседы
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
if event.object.peer_id == event.object.from_id: #Для Лс
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
except Exception as e:
print(repr(e))
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="ТОКЕН")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, АЙДИ ГРУППЫ)
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.method("messages.send", {**locals(), "random_id": 0})
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id: #Для беседы
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
if event.object.peer_id == event.object.from_id: #Для Лс
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
else:
send_msg(event.obj.peer_id, "Я не знаю такой команды")
except Exception as e:
print(repr(e))
import vk_api
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="ТОКЕН")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, АЙДИ ГРУППЫ)
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.method("messages.send", {**locals(), "random_id": 0})
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id: #Для беседы
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
if event.object.peer_id == event.object.from_id: #Для Лс
if event.object.text == "Привет":
send_msg(event.obj.peer_id, "Пока")
except Exception as e:
print(repr(e))
import vk_api
import random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="ВАШ ТОКЕН")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, АЙДИ ГРУППЫ)
def send_msg(peer_id: int, message: str, attachment: str = ""):
return vk.method("messages.send", {**locals(), "random_id": 0})
while True:
try:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id == event.object.from_id: #Только для лс с группой, чтобы работало в беседе == замените на !=
if event.object.text == "Рандом":
word = "0", "0", "0", "0", 'провода'
choice = random.choice(word)
if choice == "провода":
send_msg(event.obj.peer_id, f'{choice}')
else:
print ("Сообщение не отправлено")
except Exception as e:
print(repr(e))
longpoll = VkBotLongPoll(vk, group_id)
longpoll = VkBotLongPoll(vk, 253235626)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == 'album':
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("variant1", callback_data='v1')
item2 = types.InlineKeyboardButton("variant2", callback_data='v2')
markup.add(item1, item2)
bot.send_message(message.chat.id, 'Что имеено интересует', reply_markup=markup)
elif message.text == 'profile':
markup = types.InlineKeyboardMarkup(row_width=2)
item3 = types.InlineKeyboardButton("variant1", callback_data='v3')
item4 = types.InlineKeyboardButton("variant2", callback_data='v4')
markup.add(item3, item4)
bot.send_message(message.chat.id, 'Что именно интересует', reply_markup=markup)
elif message.text == 'insta':
markup = types.InlineKeyboardMarkup(row_width=2)
item5 = types.InlineKeyboardButton("variant1", callback_data='v5')
item6 = types.InlineKeyboardButton("variant2", callback_data='v6')
markup.add(item5, item6)
bot.send_message(message.chat.id, 'Что именно интересует', reply_markup=markup)
elif message.text == 'facebook':
markup = types.InlineKeyboardMarkup(row_width=2)
item7 = types.InlineKeyboardButton("variant1", callback_data='v7')
item8 = types.InlineKeyboardButton("variant2", callback_data='v8')
markup.add(item7, item8)
bot.send_message(message.chat.id, 'Что именно интересует', reply_markup=markup)
elif message.text == 'youtube':
markup = types.InlineKeyboardMarkup(row_width=2)
item9 = types.InlineKeyboardButton("variant1", callback_data='v9')
item10 = types.InlineKeyboardButton("variant2", callback_data='v10')
markup.add(item9, item10)
bot.send_message(message.chat.id, 'Что именно интересует', reply_markup=markup)
else:
bot.send_message(message.chat.id, 'Я не знаю такой команды')
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
try:
if call.message:
if call.data == 'v1':
#что должен сделать бот
elif call.data == 'v2':
#что должен сделать бот
#и так далее
except Exception as e:
print(repr(e))
if event.object.text == "Нами" or event.object.text == "нами":
photo_send = random.randint(31, 33)
vk.method("messages.send",
{
"chat_id": event.object.peer_id - 2000000000,
"attachment": "photo-193643776_4572390" + f'{photo_send}',
"random_id": random.randint(1, 2147483647)
})
text_1 = event.obj['text'].split(' ', maxsplit=1)
if text_1[0] == "Выбери" or text_1[0] == "выбери":
text_2 = text_1[1].split('или')
list = [text_2[0], text_2[1]]
change = random.choice(list)
vk.method("messages.send",
{
"chat_id": event.object.peer_id - 2000000000,
"message": "Я выбираю " + f'{change}',
"random_id": random.randint(1, 2147483647)
})
import vk_api
import random
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk = vk_api.VkApi(token="токен")
vk._auth_token()
vk.get_api()
longpoll = VkBotLongPoll(vk, айди группы)
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.peer_id != event.object.from_id:
if event.object.text == "пинг"
vk.method("messages.send",
{
"chat_id": event.object.peer_id - 2000000000,
"message": "понг",
"random_id": random.randint(1, 2147483647)
}
)