S
S
System042022-03-12 17:47:44
Bots
System04, 2022-03-12 17:47:44

Cycle of sending sqlite3 database users a message to everyone except telebot?

What is the question ...
Before that, I wrote code with entering user ids via set (), but now I changed it so that all users are added to the list of the sqlite3 table. I
didn’t change the code much, I just added the code to sqlite3:

def selectuser(self, chat_id):
        with self.connection:
            return self.cursor.execute("SELECT * FROM `userchat` WHERE `chat_id` = ?", (chat_id,)).fetchall()


And in the main block I added only a function call:
userchat = db.selectuser(message.from_user.id)
for user in users:
            if user != message.from_user.id:
                bot.send_message(user, message.text)


For the test I added to the code...
print(message)

... to see if a message was sent

. Only the cycle of sending a message to all people except themselves does not work ( Other people should also be able to send a message to others, except themselves, and when sent correctly, they should receive a message, for example ...
bot.send_message(message.from_user.id, "Сообщение отправлено!")


... by the way, it works, but there is no sending a message from a person to others)

And also, when checking the operation of the code, an error pops up:
2022-03-12 13:23:04,139 (__init__.py:688 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: chat not found"

How can I fix the code to make it work? How to avoid mistakes?

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