1

I made a python script, I use telepot package for telegram bot. I use handle(msg) this is my script:

import telepot
bot = telepot.Bot('my_token')

def handle(msg):
    bot.sendMessage(my_chat_id , 'ok')

How can I run this script? when I call handle() I got this error:

Traceback (most recent call last):
  File "address_my_script", line 7, in <module>
    handle()
TypeError: handle() missing 1 required positional argument: 'msg'
Akhil Mathew
  • 1,571
  • 3
  • 34
  • 69
samira
  • 118
  • 1
  • 2
  • 18
  • No, if i put the "msg" argument in handle() function i get this error:NameError: name 'msg' is not defined – samira Jul 24 '17 at 06:37
  • "msg" is variable for telepot handle,i cant define it.The "msg" is data about who chat with my bot, this data include chat_id , current_id, chat_type and i cant define these data – samira Jul 24 '17 at 07:24

1 Answers1

0

handle() requires a single arg. You are calling it without any. Either change handle() (and based on your code, the better option, since 'msg' is never used) or change your caller.

Joe F
  • 461
  • 5
  • 8
  • When i put the "msg" argument it tell me that : name "msg" is not defined – samira Jul 24 '17 at 06:39
  • Right. You will need to create something called "msg" and pass it to handle(), or pass None or some such non-value. But, again: either change handle() to accept zero parameters, or make msg optional, i.e., def handle(msg=None):. You may want to consider checking out some some remedial programming learning resources before trying to do actual programming. If you don't know why calling handle() fails, or why calling handle(msg) without previously defining msg fails, you are lacking crucial programming fundamentals. Perhaps you will find "How to Think Like a Computer Scientist" useful. – Joe F Jul 25 '17 at 07:25
  • when i use handle(msg=None) it works when i give my_chat_id as an integer number(for example my chat_id is 999999)but when my chat_id is variable and i didn't define any number for it , when i call handle(msg=None) or handle(msg) , it doesn't work and i get errors.yes you are all right i am new in python.thank you for your reply – samira Jul 26 '17 at 07:27