I am using telethon in python. When I write .set 14 in Telegram, I want to receive the number 14 and define it as a variable.
@client.on(telethon.events.NewMessage(outgoing=True))
async def outgoing(m):
global ss
if m.text==".set":
ss=[int(s) for s in m.split() if s.isdigit()]
But when I test it, I get the following error
AttributeError: 'Message' object has no attribute 'split'
Does anyone have a solution to this issue?
CodePudding user response:
That error message means that the m
variable is a Message
object and the Message
object doesn't have a split
method. Check out the API for the Message
object here.
If you are trying to access the string of the message you need to use the text
or raw-text
attributes.
ss=[int(s) for s in m.text.split() if s.isdigit()]
you will also want to change the if m.text=='.set':
because right now it only executes the list comprehension if it is exactly '.set' which means there will never be any numbers in the text string.