Python 嵌入图像问题

Python 嵌入图像问题,python,python-3.x,discord,discord.py,Python,Python 3.x,Discord,Discord.py,我对嵌入中的图像有问题 我从列表中选择一个随机字符串(这是一个指向cat图像的链接),然后嵌入应该发布该图像,但是,它不是,它只是看起来像这样: 如果我将链接放到浏览器中,它们就可以正常工作。 我尝试使用importrandom和random.choice,但这也不起作用 import discord from discord.ext import commands from datetime import datetime import random class catc: def

我对嵌入中的图像有问题

我从列表中选择一个随机字符串(这是一个指向cat图像的链接),然后嵌入应该发布该图像,但是,它不是,它只是看起来像这样:

如果我将链接放到浏览器中,它们就可以正常工作。
我尝试使用import
random
random.choice
,但这也不起作用

import discord
from discord.ext import commands
from datetime import datetime
import random

class catc:
    def __init__(self, bot):
        self.bot = bot
    @commands.command(pass_context=True)
    async def cat(self, ctx):
        f=open("cat.txt","r")
        v=f.read()
        f.close()
        fi = v.split(',')
        pe=random.randint(0,41)
        re=fi[pe]
        print(re)
        embed = discord.Embed(title="title", color=0x309bf3)
        embed.set_image(url="https://i.imgur.com/xJifyGMb.jpg")
        embed.set_footer(text="Nami Bot")
        await self.bot.say(embed=embed)

def setup(bot):
    bot.add_cog(catc(bot))

因此,为了使代码正常工作,您必须将图片的URL更改为其他任何内容
例如,我将同一张图片重新上传到imgur并粘贴了链接,现在它可以正常工作了

embed.set\u图像(url=”https://i.imgur.com/SJgskbM.jpg“”

这可能与imgur的直接链接有关,但我不确定

完整工作代码:

齿轮(cat_pics.py)

main.py


是的。我知道这听起来很愚蠢,但我再试了一次,它仍然无法与任何imgur链接一起工作。新的url似乎对我有效,我将发布整个代码,看看是否有任何差异可能会干扰它的工作
import discord
from discord.ext import commands
import random

class catc:
  def __init__(self, bot):
    self.bot = bot
  @commands.command(pass_context=True)
  async def cat(self, ctx):
    with open('something.txt') as f:
      mylist = list(f)
    a = random.choice(mylist)
    print(a)
    embed = discord.Embed(title="title", color=0x309bf3)
    embed.set_image(url="https://i.imgur.com/SJgskbM.jpg")
    embed.set_footer(text="Nami Bot")
    await self.bot.say(embed=embed)

def setup(bot):
  bot.add_cog(catc(bot))
from discord.ext.commands import Bot

startup_extensions = ["cat_pics"]
client = Bot(command_prefix='!')

@client.command()
async def load(extension_name : str):
  """Loads an extension."""
  try:
    client.load_extension(extension_name)
  except (AttributeError, ImportError) as e:
    await client.say("```py\n{}: {}\n```".format(type(e).__name__, str(e)))
    return
  await client.say("{} loaded.".format(extension_name))


if __name__ == "__main__":
  for extension in startup_extensions:
    try:
      client.load_extension(extension)
    except Exception as e:
      exc = '{}: {}'.format(type(e).__name__, e)
      print('Failed to load extension {}\n{}'.format(extension, exc))

  client.run('TOKEN')