TypeError: format() argument after ** must be a mapping, not Attachment
TypeError: format() argument after ** must be a mapping, not Attachment
您好,我正在尝试解决我的 discord 机器人的日志模块问题。我收到错误 TypeError: format() argument after ** must be a mapping, not Attachment
cogs\core.py", line 351, in on_message_delete
delmessage.add_field(name='**Attachment**', value='[{filename}]({url})'.format(**attachment), inline=True)
TypeError: format() argument after ** must be a mapping, not Attachment
我不确定是什么原因造成的。
这是我正在处理的内容:
async def on_message_delete(self, message):
guild = message.guild
author = message.author
bot_member = guild.me
time = dt.datetime.utcnow()
now = dt.datetime.utcnow()
if author.bot:
return
if not guild:
return
cleanmsg = message.content
for i in message.mentions:
cleanmsg = cleanmsg.replace(i.mention, str(i))
name = author
name = " ~ ".join((name.name, name.nick)) if name.nick else name.name
changes = True
if author.id != self.bot.user.id:
infomessage = "A message by {} was deleted.".format(message.author.mention, message.channel.mention)
delmessage = discord.Embed(description=infomessage, colour=discord.Color.purple(), timestamp=time)
delmessage.add_field(name="Message:", value=cleanmsg)
delmessage.set_footer(text="ID: {}".format(message.author.id))
delmessage.set_author(name=name + "'s message was deleted.", icon_url=message.author.avatar_url)
if message.attachments:
for attachment in message.attachments:
delmessage.add_field(name='**Attachment**', value='[{filename}]({url})'.format(**attachment), inline=True)
await self.bot.send_log_message(guild, embed=delmessage)
您不能通过解包对象来获取它们的属性(除非对象是专门为此设计的)。相反,您可以编写格式字符串以通过点符号访问属性:
delmessage.add_field(name='**Attachment**', value='[{0.filename}]({0.url})'.format(attachment), inline=True)
OP 的一些信息。以这种方式访问任何 links 将不起作用。 Discord 最近更改了图像的缓存方式。如果您在图像被删除之前访问它,您可以获得缓存副本,否则如果它在您访问之前被删除,它将永远消失。
嵌入 link 并访问它只会 return 出现 403 错误。
您好,我正在尝试解决我的 discord 机器人的日志模块问题。我收到错误 TypeError: format() argument after ** must be a mapping, not Attachment
cogs\core.py", line 351, in on_message_delete
delmessage.add_field(name='**Attachment**', value='[{filename}]({url})'.format(**attachment), inline=True)
TypeError: format() argument after ** must be a mapping, not Attachment
我不确定是什么原因造成的。
这是我正在处理的内容:
async def on_message_delete(self, message):
guild = message.guild
author = message.author
bot_member = guild.me
time = dt.datetime.utcnow()
now = dt.datetime.utcnow()
if author.bot:
return
if not guild:
return
cleanmsg = message.content
for i in message.mentions:
cleanmsg = cleanmsg.replace(i.mention, str(i))
name = author
name = " ~ ".join((name.name, name.nick)) if name.nick else name.name
changes = True
if author.id != self.bot.user.id:
infomessage = "A message by {} was deleted.".format(message.author.mention, message.channel.mention)
delmessage = discord.Embed(description=infomessage, colour=discord.Color.purple(), timestamp=time)
delmessage.add_field(name="Message:", value=cleanmsg)
delmessage.set_footer(text="ID: {}".format(message.author.id))
delmessage.set_author(name=name + "'s message was deleted.", icon_url=message.author.avatar_url)
if message.attachments:
for attachment in message.attachments:
delmessage.add_field(name='**Attachment**', value='[{filename}]({url})'.format(**attachment), inline=True)
await self.bot.send_log_message(guild, embed=delmessage)
您不能通过解包对象来获取它们的属性(除非对象是专门为此设计的)。相反,您可以编写格式字符串以通过点符号访问属性:
delmessage.add_field(name='**Attachment**', value='[{0.filename}]({0.url})'.format(attachment), inline=True)
OP 的一些信息。以这种方式访问任何 links 将不起作用。 Discord 最近更改了图像的缓存方式。如果您在图像被删除之前访问它,您可以获得缓存副本,否则如果它在您访问之前被删除,它将永远消失。
嵌入 link 并访问它只会 return 出现 403 错误。