首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Discord.py嵌入本地文件

Discord.py嵌入本地文件
EN

Stack Overflow用户
提问于 2021-10-21 04:34:16
回答 1查看 136关注 0票数 2

我尝试将本地设备中的文件添加到discord.py嵌入中。下面是我的代码,虽然它不能工作,但请帮助我

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-21 11:24:08

要将本地文件用于嵌入的图像,请使用Discord的attachment://协议。(归于Lukasz)。

代码语言:javascript
复制
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)

https://discordpy.readthedocs.io/en/stable/faq.html#how-do-i-use-a-local-image-file-for-an-embed-image

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69655938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档