P
P
piki_adm2020-06-01 17:07:06
Python
piki_adm, 2020-06-01 17:07:06

Error in code 'UserXtrCounters' object is not subscriptable. How to fix?

code:

@bot.on.chat_message(text='bank', lower=True)
async def Bank(ans: Message):
chat_id = ans.chat_id
c.execute('SELECT stavki FROM chat_1 WHERE chat_id=%d' % chat_id )
res = c.fetchone()[0]
print(f'\n{res}')
bank = ''
result = res.split(';')
del result[0]
del result[-1]
bank = ' '
print(result)
for ell in result:
el = ell.split(':')
data = await bot.api.users.get(user_ids=el[0])
name = await data[0]['first_name'] + ' ' + data[0]['last_name']
bank += f"@id{el[0]}({name}) placed {el[2]} VkCoins on {el[1]}\n\n "
await ans(f'{bank}')

error
5ed50c9710bbd631784201.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2020-06-02
@piki_adm

It's not a list/dictionary, you can't take values ​​from it like that.
See what functions are available for the UserXtrCounters class. Most likely, the values ​​​​can be taken through this:
data[0].first_name or data.0.first_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question