sqlite 我试图创建一个for循环,但没有成功(有点复杂)

jvidinwx  于 2022-12-04  发布在  SQLite
关注(0)|答案(1)|浏览(223)

所以我试着在discord机器人中做一个for循环,但是无论我做什么,它都会给我错误。
这个循环是针对embed.add_field函数的,下面是我尝试的:

for i in netres:
  embed.add_field(name=f"Email: {netres[0][i[0]]}", value=f"Password: {netres[1][i]}", inline=False)

如果它能提供帮助,netres = a c.fetchall from a db.下面是netres:

netres = c.fetchall()

完整回溯为:

Ignoring exception in command buy:
Traceback (most recent call last):
  File "C:\Users\sidal\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 124, in wrapped
    ret = await coro(arg)
          ^^^^^^^^^^^^^^^
  File "C:\Users\sidal\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 980, in _invoke
    await self.callback(ctx, **kwargs)
  File "C:\Users\sidal\Desktop\sidtho\main.py", line 323, in buy
    embed.add_field(name=f"Email: {netres[0][i[0]]}", value=f"Password: {netres[1][i]}", inline=False)
                                   ~~~~~~~~~^^^^^^
TypeError: tuple indices must be integers or slices, not str

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

Traceback (most recent call last):
  File "C:\Users\sidal\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\bot.py", line 1114, in invoke_application_command  
    await ctx.command.invoke(ctx)
  File "C:\Users\sidal\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 375, in invoke
    await injected(ctx)
  File "C:\Users\sidal\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\commands\core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: tuple indices must be integers or slices, 
not str```
cs7cruho

cs7cruho1#

您只需要将元组的元素设置为整数或切片。(如果您的要求是字符串)

相关问题