python - Discord.py 嵌入本地文件
问题描述
我尝试将本地设备中的文件添加到 discord.py 嵌入中。下面是我的代码,虽然它不起作用请帮助我
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="!")
@client.command
async def pika(ctx):
file = discord.File("E:\Python\discord.py\Pikachu1.jpg", filename="image.jpg")
embed = discord.Embed(color=0xFFFFFF)
embed.set_image(url="E:\Python\discord.py\Pikachu1.jpg")
await ctx.send(file=file, embed=embed)
解决方案
要将本地文件用于嵌入的图像,请使用 Discord 的attachment://
协议。(归因于卢卡斯)。
file = discord.File("path/to/my/image.png", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png")
await channel.send(file=file, embed=embed)
推荐阅读
- mpeg-dash - DASH mpd 将 http 标头添加到所有请求
- android - 如何创建颤振图像滑块(例如 Flipkart 产品详细信息页面)
- android - 在 httpAuthHandler 使用正确的用户名/密码对后,如何使 Android webview 保存的令牌无效?
- r - 如何在 r 中获得下个月的第一个工作日
- javascript - 完成两个 Promise 后执行函数
- multithreading - 如何从循环外取消处于侦听循环中的 TCPListener?
- php - 启用 XDebug 时 [] Operator not supported for strings 当操作数为空数组时有时会发生错误
- html - Angular 中的可折叠手风琴,无需使用 JS 代码,仅使用 HTML。每当我单击按钮时,它什么也不做。请解决这个
- android - Firebase getCurrentUser 在 linkWithCredentials 之后返回 null 有时
- java - 来自 java 对象的 JPA 查询