我创建了第一个机器人并发出警告/未使用局部变量 chat_id 值
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)
#局部变量“chat_id”值未使用
#局部变量“文本”值未使用
你应该把你的功能改成这样:
@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())
将 send_message 和打印放在 get_message 内,以便使用 chat_id 和文本
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)
#局部变量“chat_id”值未使用 #局部变量“文本”值未使用
你应该把你的功能改成这样:
@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())
将 send_message 和打印放在 get_message 内,以便使用 chat_id 和文本