Q
Q
qwwwwwty2021-11-25 17:40:51
Python
qwwwwwty, 2021-11-25 17:40:51

How can I make the bot send a message on my whim to the selected Aiogram Pyrhon chat?

And how to implement so that the bot would write a message on my whim to the selected Aiogram Pyrhon chat? using args = message.get_args() (as an option). For example, I know the id of the chat where I need to write a message and the bot is present in this chat. There is also a / hellochat hello command where the hello message will go to a random conversation, and I want to implement it so that you can select the chat ID, and then the desired message. Example situation:
/hellochat hello
*bot sends message hello to random chat*
/hellochat -100200300 hello
*bot sends hello to chat with id -100200300*

I already have a draft code, but it works for random conversation

@dp.message_handler(commands=['hellochat'], commands_prefix="!/")
async def chatID_dialog(message: types.Message):
    connect = sqlite3.connect('chatID easybot 2.dp')
    cursor = connect.cursor()
    cursor.execute("SELECT * FROM chatsID ORDER BY RANDOM() LIMIT 1")
    for row in cursor.fetchall():
        chat_id = list(row)[0]
        args = message.get_args()
        titleON = f"@{message.from_user.username}"
        chatName = f"{message.chat.title}"        
        await bot.send_message(chat_id, text = (f"Вам пришло сообщение от: {titleON} из беседы: {chatName}. Сообщение: " + " " + args))
        await bot.send_message(message.chat.id, text = "Ваше сообщение успешно отправлено в рандомную беседу✅")

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question