Python Telegram Bot error in deleting message and sending message

60 Views Asked by At
@bot.message_handler(commands=['stopgame'])

def test2(message):

    bot.send_message(message.chat.id,'GIOCO FINITO!')

    gamerunning = false

 

@bot.message_handler(commands=['startgame'])

def test(message):

    if(message.from_user.id == 785959524):

        bot.send_message(message.chat.id, 'GIOCO INIZIATO!')

        gamerunning = true

    

 

@bot.message_handler(func=lambda message: True)

def echo_message(message):

    if gamerunning is true:

        d = (message[-1].message_id)

        

        if message.text.lower() in [(x)]:

            x = x+1

 

        elif message.text.lower() in ["169"]:

            bot.send_message(message.chat.id, 'Test message')

     

        else: delete_message(d,-1001681209629)

I can't make to work the party After "if gamerunning is true:"

Is not a bool problema, i also tried assigning a variabile ti 1 and 0

Basically Is a bot that works in a group, where people have to count, and if they don't continue correctly, the bot Will delete the message, so i give an example of a chat:

In the group:

1 (ok)

2 (ok)

3 (ok)

5 (delete)

8 (delete)

Ajdjdk (delete)

4 (ok)

Also i get this error, but i don't know what Is causing It

1

There are 1 best solutions below

0
On

First of all, you declare gamerunning true and false without capital letters. Make sure to declare them with capital letters.

Second, start with global variables for both gamerunning and x. Now you start using x without referencing it anywhere else (could be in the rest of your code, but please provide more details in the future).

Probably this should be a comment, but I cannot comment since I am a new contributor.