python - 如果用户在描述中输入图像 URL 或附加图像,有没有办法让我的机器人嵌入图像?
问题描述
我做了一个嵌入命令,我的机器人会询问嵌入的标题、嵌入的描述以及用户希望发送嵌入的渠道。它运作良好,但每当有人在描述中输入图像 URL 链接时,我的机器人只会显示链接而不是图像。
我尝试使用embed.set_image
它正在工作
但是每当用户发送无链接描述时,我都会收到错误
Invalid Form Body
In embed.image.url: Not a well formed URL.
此外,当用户回复附加图像时,机器人将发送嵌入,但会将描述完全留空。
我用于描述的代码。
desc= []
await ctx.channel.send('Description that you want to be embed')
msg = await self.client.wait_for('message', check=check(ctx.author))
desc.append(msg.content)
desc1 = ''.join(desc)
embed = discord.Embed(color=0xD5A6BD, description=str(desc1),
timestamp=ctx.message.created_at)
await submit_chan.send(embed=embed)
解决方案
您的错误似乎表明 URL 无效。这是一种从输入/附件中获取图像 url 的方法。
@commands.command()
async def em(self, ctx, url=None):
if not url:
url = ctx.message.attachments[0].url
print(url)
await ctx.send(embed=Embed().set_image(url=url))
推荐阅读
- javascript - 如何从nodeJS中的子文件获取与父文件夹相同目录中的文件的绝对路径
- c - gcc - 对“libusb_init”的未定义引用
- r - 使用 R 理解插入符号中的网格
- mobile - Aframe move vr-camera-component
- node.js - DynamoDb 如何查询全局二级索引?
- scala - 如何将数据框的列值替换为与输入值匹配的空字符串?
- php - PHP中的Websocket握手连接错误
- razor - ASP.NET Core 如何在没有查询字符串的情况下使用 [asp-page] Tag Helper?
- batch-file - forfile 和 AD 主文件夹不起作用
- angular - 提交表单编辑值 ngForm