【问题标题】:Upload an embed image?上传嵌入图片?
【发布时间】:2018-05-10 22:52:29
【问题描述】:

我想知道如何让我的机器人将嵌入的图像上传到 Discord 频道。我知道如何让它发送嵌入,但我如何上传嵌入的图像? discord.py 甚至有可能吗? 请记住,我不是指您可以在嵌入图像中使用的缩略图,我想知道您是否甚至可以使用 Python 上传嵌入图像。谢谢!

【问题讨论】:

  • 这能回答你的问题吗? Attach a file in an embed (Discord.py)
  • 请参阅上面链接的帖子以获取更新的解决方案,因为 discord.py 已更改,此处的答案现已过时。

标签: python-3.x discord.py


【解决方案1】:

要在嵌入中发送图像,请使用嵌入的set_image 方法:

e = discord.Embed()
e.set_image(url="https://discordapp.com/assets/e4923594e694a21542a489471ecffa50.svg")

要从您的 PC 发送文件,请在异步分支中使用 send_file 方法或在重写分支中使用 send 方法。

# Async
await bot.send_file(channel, "filepath.png", content="...", filename="...")

# Rewrite
file = discord.File("filepath.png", filename="...")
await channel.send("content", file=file)

【讨论】:

  • 谢谢,但我收到错误 TypeError: set_image() missing 1 required positional argument: 'self'
  • 我的错,我忘了创建类的实例,让我编辑我的答案。
  • 作为图片的URL,我可以放https://i.imgur.com/5nqpFiF.jpg这样的东西吗?我不再收到 TypeError,但现在什么也没发生,可能与 URL 有关。
  • 这样的直接图片链接应该有效。当您将嵌入发送到频道时,它应该将该 URL 处的图像添加到嵌入中。
  • 写答案时,PyPI 上的 discord.py 是 0.16 版本,或者是 Async 分支。但现在,当前版本是 1.x,它是 Rewrite 分支。两者都在这里,因为它们都可以使用多年,但直到最近才将 Rewrite 纳入 PyPI 的主分支
猜你喜欢
  • 2017-04-08
  • 2017-10-12
  • 1970-01-01
  • 1970-01-01
  • 2015-08-26
  • 2021-03-19
  • 1970-01-01
  • 1970-01-01
  • 2010-12-02
相关资源
最近更新 更多