Issue
I have a script to copy and split messages from source to destination chats used pyrogram python library. Script should split messages bigger than 300 symbols on separated messages and he is doing it without any problems if there is no media content in the message. Messages with media content (photos, audios, videos) are just ignored and never get copied in destination chat any more.
Do someone has an idea how can i make script copy and split every message, no matter if there is a content or not and it is more than 300 symbols?
Code:
#!/usr/bin/env python3
from pyrogram import Client
from pyrogram import filters
# ~~~~~~ CONFIG ~~~~~~~~ #
ACCOUNT = "@account"
PHONE_NR = 'number'
API_ID = APIID
API_HASH = "APIHASH"
app = Client( ACCOUNT, phone_number=PHONE_NR, api_id=API_ID, api_hash=API_HASH )
### CHAT ID
# Variables
SOURCE_CHAT_TEST = chat_id
TARGET_CHAT_TEST = chat_id
# ~~~~~~~~~~~~~~~~~~~~~~ #
# Commands
@app.on_message(filters.text & filters.chat(SOURCE_CHAT_TEST))
def copy_to_channel(client, message):
if len(message.text) >= 300:
for i in range(0, len(message.text), 300):
client.send_message(
chat_id=TARGET_CHAT_TEST,
text=message.text[i:i+300])
else:
message.copy( chat_id=TARGET_CHAT_TEST )
app.run()
Solution
Try this to check for the existence of a text regardless message type:
@app.on_message(filters.chat(SOURCE_CHAT_TEST))
def copy_to_channel(client, message):
if message.text:
if len(message.text) >= 300:
for i in range(0, len(message.text), 300):
client.send_message(
chat_id=TARGET_CHAT_TEST,
text=message.text[i:i+300])
else:
message.copy( chat_id=TARGET_CHAT_TEST )
else:
pass
Answered By - RJ Adriaansen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.