【发布时间】:2022-12-10 09:29:08
【问题描述】:
每当我尝试使用此命令时,我都会不断收到此错误,并且我一直在测试它,但尽管查看了其他问题,我仍然无法弄清楚问题是什么。
Traceback (most recent call last):
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 190, in wrapped
ret = await coro(*args, **kwargs)
File "/home/container/main.py", line 398, in warnings
embed.add_field(name=f"{warn['reason']}", value=f"<@{warn['moderator_id']}>", inline=False)
TypeError: string indices must be integers
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/bot.py", line 1347, in invoke
await ctx.command.invoke(ctx)
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 986, in invoke
await injected(*ctx.args, **ctx.kwargs) # type: ignore
File "/home/container/.local/lib/python3.9/site-packages/discord/ext/commands/core.py", line 199, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: string indices must be integers
这是我的代码
@client.hybrid_command(name = "warnings", with_app_command=True, description="View the warnings of a member", aliases=["punishments"])
@commands.is_owner()
async def warnings(ctx, member: discord.Member = None):
if member == None:
await ctx.reply("A Member is required")
else:
check = warndb.warn_logs.find_one({"user_id": member.id})
if check is None:
await ctx.reply("This user has no warns")
else:
embed = discord.Embed(color=embedcolor, title=f"{member.name}'s warnings")
print(check)
for warn in check:
embed.add_field(name=f"{warn['reason']}", value=f"<@{warn['moderator_id']}>", inline=False)
await ctx.send(embed=embed)
如果有人知道请帮助我我已经处理这个问题一段时间了
【问题讨论】:
-
不是真的,我仍然很困惑
-
您是否尝试过打印
warn的样子?因为它是一个字符串而不是你认为的任何东西
标签: python discord discord.py