При вводе команды - ошибка "TypeError: string indices must be integers"

Хотел подружить один API с Discord, но выдаёт ошибку, когда ввожу команду ">>profile {ник игрока}". Ошибка:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "C:\Users\Артем\Desktop\VimeBot.py", line 16, in profile
    await ctx.send(f"""```Ник: {str(profile['username'])}
TypeError: string indices must be integers

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Python39\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "C:\Python39\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: string indices must be integers

Функция, которая отвечает за эту команду:

async def profile(ctx, arg1):
    profile = requests.get(f"https://api.vimeworld.ru/user/name/{arg1}").text
    jsonprofile = json.loads(profile)
    await ctx.send(f"""```Ник: {str(profile['username'])}
ID: {profile['id']}```""")

Ответы (1 шт):

Автор решения: CrazyElf
profile = requests.get(f"https://api.vimeworld.ru/user/name/{arg1}").text
jsonprofile = json.loads(profile)
await ctx.send(f"""```Ник: {str(profile['username'])}

Судя по вашему коду, у вас элементарная описка. Вам нужно было обращаться к jsonprofile['username']. Но ещё более правильно сразу получать json из request, а не парсить как json "вручную" текст ответа на запрос, судя по всему задумка была именно такая изначально. Кроме того, в ответе приходит список пользователей, по нему нужно итерироваться:

profile = requests.get(f"https://api.vimeworld.ru/user/name/{arg1}").json() # <-- изменено
for user in profile: # <-- добавлен цикл
    await ctx.send(f"""```Ник: {user['username']} # <-- изменено
→ Ссылка