Answer the question
In order to leave comments, you need to log in
How to check where user wrote?
I need to make one bot for chat and commands.
The chat bot must accept commands. In private messages must respond to prompts on the keyboard.
those. let's say the bot should not respond to the / start command in the chat, but only in PM with the bot
@dp.message_handler(commands=['start'])
async def process_start_command(message: types.Message):
await message.answer("Добро пожаловать в бота сети «ПарОк» по городу Волгоград")
@dp.message_handler(is_admin=True, commands=["ban"], commands_prefix="!/")
async def cmd_ban(message: types.Message):
if not message.reply_to_message:
await message.reply("Эта команда должна быть ответом на сообщение!")
return
await message.bot.delete_message(chat_id=config.GROUP_ID, message_id=message.message_id)
await message.bot.kick_chat_member(chat_id=config.GROUP_ID, user_id=message.reply_to_message.from_user.id)
await message.reply_to_message.reply("Пользавтель заблокирован")
Answer the question
In order to leave comments, you need to log in
The official FAQ has the same .
How can I distinguish a User and a GroupChat in message.chat?
Telegram Bot API support new type Chat for message.chat.
Check the type attribute in Chat object:
if message.chat.type == "private":
# private chat message
if message.chat.type == "group":
# group chat message
if message.chat.type == "supergroup":
# supergroup chat message
if message.chat.type == "channel":
# channel message
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question