Home>

I am using Python and the Aiogram library. My bot has a database where it records the group members and at the command/allhe must make a general gathering in the group, that is, convene all the group members by mentioning them in the message sent to them. I know you can do this by pinning a message, but that's not what I want. I have my own version of the general collection bot, here is the source code:

import logging
from aiogram.contrib.fsm_storage.memory import MemoryStorage
import random
import sqlite3
import time
API_TOKEN= '....'
logging.basicConfig (level= logging.INFO)
bot= Bot (token= API_TOKEN)
dp= Dispatcher (bot)
def db ():
    con= sqlite3.connect ('zazivala.db')
    cur= con.cursor ()
    cur.execute ('CREATE TABLE IF NOT EXISTS db (users INTEGER, chats INTEGER)')
    con.commit ()
@ dp.message_handler (text= '/add')
async def new_commands (message: types.Message):
    con= sqlite3.connect ('zazivala.db')
    cur= con.cursor ()
    result= cur.execute ('SELECT users FROM db WHERE users=? AND chats=?', (message.from_user.id, message.chat.id)). fetchone ()
    if len (str (result))== 4:
        cur.execute ('INSERT INTO db (users, chats) VALUES (?,?)', (message.from_user.id, message.chat.id))
        con.commit ()
        await message.reply (text= 'Added you to this chat's database')
    else:
        await message.reply (text= 'You are already in the database of this chat')
@ dp.message_handler (content_types= ["left_chat_member"])
async def left_members (message):
    con= sqlite3.connect ('zazivala.db')
    cur= con.cursor ()
    cur.execute ('DELETE FROM db WHERE users=?', (message.from_user.id,))
    con.commit ()
@ dp.message_handler (text= '/all')
async def call_all_users (message: types.Message):
    con= sqlite3.connect ('zazivala.db')
    cur= con.cursor ()
    alls= cur.execute ('SELECT users FROM db WHERE chats=?', (message.chat.id,))
    alls= alls.fetchall ()
    for user in alls:
        text= ""
        text += f '{user}'. replace ('(', '') .replace (',', ''). replace (')', ''). replace ('', '')
        await message.answer (text= f '<
a href= "https: //tg: //user? id= {text}" >
General fee <
/a >
', parse_mode= types.ParseMode.HTML)
    await message.answer ('General collection completed successfully')
@ dp.message_handler (text= '/remove')
async def remove_user (message: types.Message):
    con= sqlite3.connect ('zazivala.db')
    cur= con.cursor ()
    await message.answer ('✅ Your profile has been updated')
    cur.execute (f'UPDATE db SET users=? WHERE chats=? AND users=? ', (message.from_user.id, message.chat.id, message.from_user.id))
    con.commit ()
if __name__== "__main__":
    db ()
    executor.start_polling (dp, skip_updates= True) ,
In my version, the bot sends a message, but with this message it cannot mention the members of the group. And I do not know how to implement it differently, and I ask you to help.

How do you want to mention all contributors in a post? Nicky?

ProgerOffline2021-11-23 14:21:11

Some do not have nicknames, so try somehow through ID

Dragon's play2021-11-23 14:21:11

Kore.telegram.org /bots /api # formatting options

ProgerOffline2021-11-23 14:21:11

No, it doesn't work that way

Dragon's play2021-11-23 14:21:11

Works, here is an example replit.com/@ProgerOffline/MentionUser#main.py

ProgerOffline2021-11-23 14:21:11