基本上,当我运行一个普通的 dm 命令时,它每次都会正确地 dms 用户,但是在我添加 dm 部分之前该命令工作正常,所以我不知道错误指的是哪一行。通常它不会给我一个错误,但它根本不会做任何事情,所以我添加一个异常来查找“列表索引超出范围”我可能在 embed.fields 的 for 字段中的一个想法,但我是不确定...
async def tag(ctx, message:int, member: discord.Member, action, *, args):
try:
channel = await client.fetch_channel(client.channel)
message = await channel.fetch_message(message)
embed = message.embeds[0]
if member is not None:
channel1 = member.dm_channel
if channel1 is None:
channel1 = await member.create_dm()
await channel1.send('test')
if action == "approve":
embed_dict = embed.to_dict()
for field in embed_dict["fields"]:
if field["name"] == "status":
field["value"] += f"```python\n{ctx.message.author} tagged this suggestion as **Approved**\nReason: {args}```"
embed = discord.Embed.from_dict(embed_dict)
await message.edit(embed=embed)
elif action == "deny":
embed_dict = embed.to_dict()
for field in embed_dict["fields"]:
if field["name"] == "status":
field["value"] += f"```python\n{ctx.message.author} tagged this suggestion as **Denied**\nReason: {args}```"
embed = discord.Embed.from_dict(embed_dict)
await message.edit(embed=embed)
else:
ctx.send('please specify approve or deny after the member argument')
except Exception as e:
print(e)
这是我的代码。它需要一个嵌入并添加一个“评论”,您可以将其调用到嵌入中。
答案 0 :(得分:1)
错误是由 SingleChildScrollView
这一行引起的,因为这是您尝试索引列表时唯一的一行
这显示了什么?:
获取的消息没有嵌入,因此 message.embeds 是一个空列表 embed = message.embeds[0]
,因此索引 0 处没有元素,因此会引发错误。
确保使用完美的消息 ID