Answer the question
In order to leave comments, you need to log in
Why is the split function not working?
I just started to learn coding, so I apologize for the stupid question, but I did not find the answer on the internet
import config
import logging
from aiogram import Bot, Dispatcher, executor, types
logging.basicConfig(level=logging.INFO)
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
@dp.message_handler()
async def addrifm1(message: types.Message):
mes = types.message
list = mes.split(",")
await message.reply(" async def rifm1(message: types.Message):")
await message.reply("if", list[1], " in message.text:")
await message.reply("await message.reply(", list[2], ")")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
Answer the question
In order to leave comments, you need to log in
Try wrapping mes from the line list = mes.split(",") in the dir method like this:
dir(mes) and print it.
All available methods will be displayed, among them there will be no split method, this is what caused the error.
You are getting an error because aiogram uses its own data type in the described case. The split() method works if the object is a string.
You can get a dictionary containing information about the user and his message, and then pass the value of the message to the list by key (the message will be split into separate words when a comma character occurs):
import config
import logging
from aiogram import Bot, Dispatcher, executor, types
logging.basicConfig(level=logging.INFO)
bot = Bot(token='')
dp = Dispatcher(bot)
@dp.message_handler()
async def addrifm1(message: types.Message):
mes = message
list = mes['text'].split(",")
await message.reply(" async def rifm1(message: types.Message):")
await message.reply("if", list[1], " in message.text:")
await message.reply("await message.reply(", list[2], ")")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question