1

I want a create a bot that add or leave "points". For do this i use for every user a single txt file nominated with they id. For add points i wanna do a replyed message with /addkarma (number of points) and i want add karma (the points) at the user who i replyed the message (karma=points). How i do it? Everytime i do print(message.reply_to_message.json.from.id) for check what bot take from this, python give me a error like this

print(message.reply_to_message.json.from.id)
                                    ^^^^
SyntaxError: invalid syntax

please help

import telebot
import os



bot = telebot.TeleBot(TOKEN)

def newuser(points,id):
    with open(f"{id}.txt","w") as f:
        f.write(points)

@bot.message_handler(commands=['addkarma'])
def user(username,points,message):
        file = os.path.exists(f'/users/{id}.txt')
        if not file:
            newuser(points,id)
        id = message.reply_to_message.json.from.id
        file_name = os.path.basename(f'/users/{id}.txt')

thats all my code and what i try to do

ps.Is my first post here, not really good to write english and wanna help, please forgive me for eng errors. Also pretty new to telegram bots :)

  • You might be using an attribute to access a dictionary value - from a quick look at github, might it be `...reply_to_message.from_user.id`? – Jack Deeth Oct 10 '22 at 21:48
  • usually in Python, json data is stored as a `dict` and is addressed like this: `blahaj.json()["from"]["id"]` - unless whoever wrote `blahaj` did some extra work – Jack Deeth Oct 10 '22 at 21:50
  • Sorry, what mean "access to the dictionary value" i know basic of python never user dictionary value or else, can you explain to me better? – Alessio Fortè Oct 10 '22 at 23:34
  • Python dictionaries: `kallax = {"billy": 42, "lack": 123}`. here `kallax` is a dictionary, and `billy` and `lack` are its keys. You get the values with `kallax["billy"]` (== 42). I think in Javascript you'd write `kallax.billy` to get the 42. – Jack Deeth Oct 10 '22 at 23:48
  • i try this right now but give me some error, so this remain i need get the user id of the replyed message – Alessio Fortè Oct 11 '22 at 13:12

0 Answers0