【问题标题】:Discord.py Embed Local FileDiscord.py 嵌入本地文件
【发布时间】:2021-12-07 20:41:32
【问题描述】:

我尝试将本地设备中的文件添加到 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)

【问题讨论】:

  • 请准确解释这里不工作的地方。也许您也可以发布回溯?
  • 别想了,你只设置颜色和添加图像。难道 embed 有必需的参数?试试embed = discord.Embed(color= 0xFFFFFF, title="test")。请添加更多关于其他人所说的不起作用的信息。
  • 再试一试,将@client.command更改为@client.command()

标签: python error-handling discord discord.py


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-17
    • 2021-10-26
    • 2018-07-09
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-08-18
    相关资源
    最近更新 更多