Discord Bot python TypeError: string indices must be integers

Viewed 32

This in the beginning hard problem was in the end easy fixed :)

2 Answers

I think you are trying to do slice operation in string. example:

>>> a
'string'

>>> a[0]
's'

>>> a["s"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: string indices must be integers
>>>

hope this helps

I am not sure how this works. But if you have a settings.json file and that file is there in the directory where this py file exists, then the below code should work.

bot = commands.Bot(command_prefix='/', intents=discord.Intents.all())
settings = None
with open("./settings.json", "r") as settings_file:
    data = settings_file.read()
    settings = json.loads(data)

Related