Problem: I used FSM Telegram Bot and in the end bot changes chat user to chat admin and changes admin’s custom title . But I have a problem with changing custom title, this is console output:
ERROR:aiogram.event:Cause exception while process update id=XXXXXXXX by bot id=XXXXXXXX
TelegramBadRequest: Telegram server says - Bad Request: RIGHT_FORBIDDEN
Code:
@dp.message(CommandStart())
async def start_questionnaire_process(message: Message, state: FSMContext):
async with ChatActionSender.typing(bot=bot, chat_id=message.chat.id):
await asyncio.sleep(2)
await message.answer('Hi. What is your name: ')
await state.set_state(Form.name)
@dp.message(F.text, Form.name)
async def capture_name(message: Message, state: FSMContext):
await state.update_data(name=message.text)
async with ChatActionSender.typing(bot=bot, chat_id=message.chat.id):
await asyncio.sleep(2)
await message.answer('How old a you: ')
await state.set_state(Form.age)
@dp.message(F.text, Form.age)
async def capture_age(message: Message, state: FSMContext):
check_age = extract_number(message.text)
await state.update_data(age=check_age)
data = await state.get_data()
msg_text = (f'Name:{data.get("name")}/Age:{data.get("age")}')
await message.answer(msg_text)
await state.clear()
#####
await message.bot.promote_chat_member(chat_id=CHANNEL_ID,
user_id=message.from_user.id,
request_timeout=2)
await message.bot.set_chat_administrator_custom_title(chat_id=CHANNEL_ID,
user_id=message.from_user.id,
request_timeout=2,
custom_title=msg_text)
Could your please help me?
Edit: I do not have a problem with promote_chat_member()
, I have a problem with set_chat_administrator_custom_title()
. With first run /start
in console output Bad Request: RIGHT_FORBIDDEN
, error in function set_chat_administrator_custom_title()
and with second run /start
, function `set_chat_administrator_custom_title() finishes correctly.
Bot has only one permission "Add new Admins".
2
Answers
Check Bot Permissions:
bot.
Promote User with Bot:
I ran into the same problem and seemed to have solved it.
If bot trying to change custom title for admin, that not promoted by bot itself, it cannot do it. In other words – bot can change custom title only for admins promoted by it.