File "bot-test.py", line 4, in <module>
from loader import dp
ImportError: cannot import name 'dp' from 'loader' (unknown location)
from telethon import TelegramClient, events
api_id = 11id6
api_hash = "d53aцифрыcdaecf0cбуквы90caa"
target_chat = -100цифры96
client = TelegramClient('my_account11', api_id, api_hash)
text1 = "MessageActionChatDeleteUser"
text2 = "MessageActionChatAddUser"
@client.on(events.chataction.ChatAction)
async def my_event_handler(event):
#print(event)
patt = str(event.action_message.action)
try:
if text1 in patt:
id_todel = event.action_message.id
await client.delete_messages(target_chat, message_ids=id_todel)
print("User left delited")
elif text2 in patt:
id_todel = event.action_message.id
await client.delete_messages(target_chat, message_ids=id_todel)
print("User add delited")
except Exception as e:
print("Error: ", e)
client.start()
client.run_until_disconnected()
import requests # импортируем библиотеки
from telethon import TelegramClient, events
from telethon.tl import types
from telethon.tl.types import PeerUser, PeerChat, PeerChannel, ChatBannedRights
from telethon.tl.functions.channels import EditBannedRequest
api_id = *********** # +**********
api_hash = '**************************'
bot_token = '*****************:********************************'
client = TelegramClient('my_account', api_id, api_hash)
bot = TelegramClient('bot', api_id, api_hash).start(bot_token=bot_token)
bad_words =["ПОИSК", "BE4EP", "ПОИSК", "Г0PЯ4UЕ", "ЗНАK0МСTVA", "", "", "", "СEKS", "ПAPTНЕР0B", ""]
@bot.on(events.ChatAction)
async def my_event_handler(event):
print("Event!")
#print(event)
#print(event.action_message.from_id.user_id)
channel = event.action_message.peer_id.channel_id
#print(channel)
method = 'getUpdates?offset=-1'
response = requests.post(
url='https://api.telegram.org/bot{0}/{1}'.format(bot_token, method),
data={'id': event.action_message.from_id.user_id}).json()
#print(response)
data = response.get("result")[0].get("message").get("from").get("first_name")
user = response.get("result")[0].get("message").get("from").get("username")
#sum = response.get("result")[0].get("message").get("from")
#print(sum)
#print(user)
#print(data)
if event.user_joined == True:
print("!!!!!!!")
for i in range(len(bad_words)):
print(bad_words[i], " not in ", data)
if bad_words[i] in data:
print("Busted", channel, user)
await client.edit_permissions(channel, user, view_messages=False)
print("Delited")
client.start()
client.run_until_disconnected()
from telethon import TelegramClient, events
api_id = 1id6
api_hash = "Moyhash"
client = TelegramClient('my_account11', api_id, api_hash)
text1 = "MessageActionChatDeleteUser"
text2 = "MessageActionChatAddUser"
@client.on(events.chataction.ChatAction)
async def my_event_handler(event):
#print(event)
pattern = str(event.action_message.action)
try:
if text1 in pattern:
id_todel = event.action_message.id
await client.delete_messages(newchat = message.chat.id, message_id=id_todel)
print("User left delited")
elif text2 in pattern:
id_todel = event.action_message.id
await client.delete_messages(newchat = message.chat.id, message_id=id_todel)
print("User add delited")
except Exception as e:
print("Error: ", e)
client.start()
client.run_until_disconnected()
При нажатии на эту кнопку