首页 > 解决方案 > 如果用户在描述中输入图像 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)

标签: pythondiscord.py

解决方案


您的错误似乎表明 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))

推荐阅读