[HELP] Incrementing Number to txt file via Twitch Command in Python

Hello,

Can someone get back to me on this ASAP if you think you can assist! Cheers.

This is perhaps a question for Python Twitch bot developers. I hope there are a few on here and hope the title is informative enough, too! Please respond or perhaps pass it on to someone who knows this!

You might have seen this functionality in Twitch streams for death counts and the like. Anyway, I’m attempting to increase an integer once a “+” prefix is entered into Twitch chat before a word, similar to a "!"command. When that occurs, I need a number to increment by 1 and save to a text file so it can continually update each time and be available for the long term. It essentially needs to read and write.

The issue I’m having currently, is the code where the counter functions are stored are throwing up undefined variable errors in a certain order, or in another order, asking for 3 positional arguments.

I’m not the greatest or the most experienced with Python, so would appreciate any help! Thanks all!

Error:
bot.send_message(f"Incremented number: {(next(number))}")
NameError: name ‘bot’ is not defined

Code:

def add_count(bot, user, message, add_count=None):
    
    if add_count is None:
        
        INCREMENT_COUNTER = "+"
        
        with open("./files/counter.txt", "r") as file:
            file.readlines(1) 
            print(file.read(1))
        
    number = 0

    if message.startswith(INCREMENT_COUNTER):
        while True:
            yield number
            number = number + 1
            number = add_count()
        
for i in range(10):
    
    bot.send_message(f"Incremented number: {(next(number))}")
    print(next(number))
    
    with open("./files/counter.txt", "w") as file:  
        file.write(next(number))


def current_count(bot, user, *args, current_count=None):
    if current_count is None:
        bot.send_message(f"Current count is: {next(number)}.")