-2

How can I have my telegramBot send automatically messages in a group?

def handle_event(event):
    #print(event)
    global amount0In
    global amount1Out
    global amount1In
    global amount0Out
    amount0In = event['args']['amount0In']
    amount1Out = event['args']['amount1Out']
    amount1In = event['args']['amount1In']
    amount0Out = event['args']['amount0Out']
    if amount0In and amount1Out != 0:
        print(f"Token Sold {amount0In /10**18}, and eth {amount1Out/10**18}")
        buy()
    else:
        print(f"Token Bought {amount0Out /10**18}, and eth {amount1In/10**18}")
        sell()

    
def buy(update,context):
            buyMessage = f"Buy!!!!\n: {amount1In/10**18}\nToken Bought: {amount0Out /10**18} \n"
            update.message.reply_text(buyMessage)       

def sell(update, context):
            sellMessage = f"Sell!!!!\n: {amount1In/10**18}\nToken Sold: {amount0Out /10**18} \n"
            update.message.reply_text(sellMessage)

In case the IF statement is met I want to send a message to a telgram group, however I cant execute the update message this way, because I keep getting this error: TypeError: buy() missing 2 required positional arguments: 'update' and 'context'

How can I fix this?

Adriaan
  • 17,741
  • 7
  • 42
  • 75
jimmyblue
  • 1
  • 2

1 Answers1

1

To send a message, all you need is an instance of telegram.Bot. Please have a look at the introduction to the API for more details. The functions buy and sell look like callback functions for handler. Since you are apparently not using python-telegram-bots handler setup to handle the event, there is no sense in defining those functions to accept the update and context arguments.


Disclaimer: I'm currently the maintainer of python-telegram-bot.

CallMeStag
  • 5,467
  • 1
  • 7
  • 22
  • 1
    Hi CallMeStag. Thanks for your contribution. As far as I can tell, you are following the guidelines of this community and spend time and effort to help another user. You even disclose your affiliation, which other helpfully minded users sometimes forget. – Yunnosch Nov 07 '22 at 17:49