Skip to content
Advertisement

I create the first bot and a warning comes out / local variable chat_id value is not used

from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor

 bot: Bot = Bot(token='TOKEN')
 dp = Dispatcher(bot)


@dp.message_handler()
async def get_message(message: types.Message):
    chat_id = message.chat.id
    text = "shiz ?"


 sent_message = await bot.send_message(chat_id=chat_id, text=text)

 print(sent_message.to_python())


 executor.start_polling(dp)

#local variable “chat_id” value is not used #local variable “text” value is not used

Advertisement

Answer

You should fix your function to be as such:

@dp.message_handler()
async def get_message(message: types.Message):
    chat_id = message.chat.id
    text = "shiz ?"
    sent_message = await bot.send_message(chat_id=chat_id, text=text)
    print(sent_message.to_python())

Placing the send_message and print inside the get_message in order to make use of the chat_id and text

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement