Reputation: 1436
i'm trying to build a python telegram bot but I keep getting this error and i cant fint the source of the error... details:
My Class:
class weed4us_bot():
def __init__(self, config):
self.token = self.read_token_from_config_file(config)
self.base = 'https://api.telegram.org/bot{}/'.format(self.token)
def get_updates(self, offset=None):
url = self.base + 'getUpdates?timeout=100'
if offset:
url = url + '&offset={}'.format(offset + 1)
r = requests.get(url)
return json.loads(r.content)
def send_massage(self, msg, chat_id):
url = self.base + 'sendMessage?chat_id={}&text={}'.format(chat_id, msg)
if msg is not None:
requests.get(url)
def read_token_from_config_file(config):
parser = cfg.ConfigParser()
parser.read(config)
return parser.get('creds', 'token')
My Main file:
from main_bot import weed4us_bot as bot
update_id = None
def make_reply(msg):
if msg is not None:
reply = 'okay'
return reply
while True:
print('...')
updates = bot.get_updates(offset=update_id)
updates = updates['result']
if updates:
for item in updates:
update_id = item['update_id']
try:
message = item['message']['text']
except:
message = None
from_ = item['message']['from']['id']
reply = make_reply(message)
bot.send_massage(reply, From_)
and I keep getting this error:
TypeError: get_updates() missing 1 required positional argument: 'self'
can someone please help me out?
Upvotes: 0
Views: 2294
Reputation: 1039
get_updates
is a method from class weed4us_bot
so if you want to call this method, you need to call it on an object of this class. So first you need to create an object of class: obj = weed4us_bot()
, and then call this method obj.get_updates(offset=update_id)
.
There is also a second possible way to call this method: weed4us_bot.get_updates(object, offset=update_id)
but still you need to create an object of this class.
Your error occurs in this line: updates = bot.get_updates(offset=update_id)
. To fix it you could first create object of class weed4us_bot: bot_object = bot(some_config)
and then call method on object: bot_object.get_updates(offset=update_id)
. Or pass weed4us_bot
object as self. You can do it in this way: bot.get_updates(bot(some_config), offset=update_id)
Upvotes: 2