Home > Software engineering >  TypeError: sendTrade() missing 1 required positional argument: from class function
TypeError: sendTrade() missing 1 required positional argument: from class function

Time:01-14

I'm trying to access a function inside the class which houses the Discord bot. Getting

TypeError: sendTrade() missing 1 required positional argument: 'valuta'.

MyClient.sendTrade() is called from within a loop in another function which is run inside a thread.

def monitor():
    if stuff here is true:
        MyClient.sendTrade(pris, volym, befattning, getTicker(isin), namn, valuta)

class MyClient(discord.Client):
    async def on_ready(self):
        print('Logged in as')
        print(self.user.name)
        print(self.user.id)
        print('------')
    async def sendTrade(self, pris, volym, befattning, ticker, namn, valuta):
        id = 930909133224435737
        channel = MyClient.get_channel(id)
        await channel.message.send(""   str(befattning)   " köpte "   str(ticker)   " för "   str(float(pris)*float(volym)/1000000)   " M"   valuta  " i "   namn   " för "   str(pris)   " per aktie")


if __name__ == '__main__':
    Thread(target=clearLst).start()
    Thread(target=monitor).start()
    client = MyClient()
    client.run(token)

CodePudding user response:

You are calling sendTrade as if it is a static method (on the class), but the method itself is declared as an instance method, so you should call it on client and not on MyClient.

Make sure that client is initialised before accessing it.

There are multiple ways to do that. For instance, you could make monitor a method of the class, and then you have the instance as self.

  •  Tags:  
  • Related