python - 为什么我不能将嵌入的图像设置为用户发送的附件?
问题描述
制作一个允许用户报告错误的命令。我想要它,这样你就可以在错误中包含一个图像,这样你就可以展示一个视觉示例,除了我没有的东西不起作用,并且在查看文档时,这应该可以工作。
我遇到的问题是嵌入没有发送。当我删除bugEmbed.set_image()
它时,它再次起作用。
@commands.command()
async def bug(self, ctx, *, bugReport=None):
"""Command that allows users to report bugs about the bug"""
channel = self.client.get_channel(864211572218265610)
bugEmbed = discord.Embed(
title=f"Bug Report",
description=bugReport,
color= 0xFFFF00
)
bugEmbed.add_field(
name="Reported by",
value=f"<@{ctx.author.id}>"
)
bugEmbed.set_footer(
text="",
icon_url=ctx.author.avatar_url
)
bugEmbed.set_image(
url=bugReport.attachments.url
)
if bugReport is None:
await ctx.send("You didn't include a bug with the report! Try again.")
await channel.send(embed=bugEmbed)
解决方案
问题可能与attachments
列表有关,因此您无法访问名为 url 的属性,这意味着您必须执行以下操作:
if len(bugReport.attachments):
bugEmbed.set_image(
url=bugReport.attachments[0].url
)
编辑:好的,所以问题是您试图从中获取附件,bugReport
这只是您传递的文本,您真正想要做的是从上下文(ctx)中获取该数据
if len(ctx.message.attachments):
bugEmbed.set_image(
url=ctx.message.attachments[0].url
)
推荐阅读
- ubuntu - ubuntu 18.04 上的 Apt 错误:无法握手:拉取函数中的错误
- javascript - 将参数从 .Net 中的 Aspx 传递给 Common.js
- scala - 如何在 Scaladoc 中启用编译器插件?
- asp.net - 如何调整数据gridview ASP的大小
- php - 如何在 pdo 中计算和自动创建 bindParams?
- python - 为什么我的 Twitter 机器人发布的内容超出预期?
- c# - 更新到 Asp.Net Core 3 的身份项目提供 wwwroot 文件夹
- javascript - 如何在 Discord.Js 中创建用户特定频道?
- c# - Windows 身份验证在 Windows Server 2012 R2 上不起作用
- reactjs - 无法浏览器在 React App 中缓存 Cloud Front 提供的图像