from telegram.ext import Updater, CommandHandler
import logging
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Your bot's token
TOKEN = 'YOUR_BOT_TOKEN'
# The chat id of the channel
CHAT_ID = 'YOUR_CHAT_ID'
# Create a TelegramBot object
bot = TelegramBot(TOKEN)
# Define a function that sends a message to the channel and deletes the previous message
def send_message(bot, update, message):
# Send the message
sent_message = bot.send_message(chat_id=CHAT_ID, text=message)
# Delete the previous message
bot.delete_message(chat_id=CHAT_ID, message_id=sent_message.message_id - 1)
# Create an Updater object
updater = Updater(TOKEN)
# Create a CommandHandler to handle the '/send' command
send_handler = CommandHandler('send', send_message)
# Add the send_handler to the dispatcher
updater.dispatcher.add_handler(send_handler)
# Start the bot
updater.start_polling()