Ask coding questions

← Back to all posts
TypeError: string indices must be integers | Discord.py
DwellerIgor (1)

So I have a line in main.py levelling = cluster["discord"]["levelling"], but i think i need to use numbers instead of 'discord' and 'levelling': levelling = cluster[0][1]. But i dont understand which numbers do i put in there. Thank you!

Comments
hotnewtop
VulcanWM (2898)

cluster is a list and you need to enter the index of the db in the list cluster and the index of collection in the list of the db

DwellerIgor (1)

but what should i put instead of levelling = cluster["discord"]["levelling"]? Sorry, im really confused @VulcanWM

VulcanWM (2898)

so do:

clusterindex = cluster.index("discord"}
thedb = cluster[clusterindex]
dbindex = thedb.index("levelling")
levelling = thedb[dbindex]

@DwellerIgor

DwellerIgor (1)

ValueError: substring not found @VulcanWM

DwellerIgor (1)

Traceback (most recent call last):
File "main.py", line 5, in <module>
import levelsys
File "/home/runner/THANOS-LEVELSYS/levelsys.py", line 17, in <module>
clusterindex = cluster.index("discord")
ValueError: substring not found

VulcanWM (2898)

i dont get what you are trying to do. are you trying to use mongodb? @DwellerIgor

VulcanWM (2898)

If you are trying to use mongodb, then do:

import pymongo
cluster = pymongo.MongoClient(os.getenv("cluster"))
levelling = cluster["discord"]["levelling"]

@DwellerIgor

DwellerIgor (1)

well, i fixed that, but i get this again pymongo.errors.ConfigurationError: A DNS label is empty. @VulcanWM