Discordpy、Praw、获取链接的img预览,或者如果没有';t一个链接就在那里';附加了一个img,嵌入那个

Discordpy、Praw、获取链接的img预览,或者如果没有';t一个链接就在那里';附加了一个img,嵌入那个,discord,discord.py,discord.py-rewrite,reddit,praw,Discord,Discord.py,Discord.py Rewrite,Reddit,Praw,我正在使用discordpy和Praw模块访问Reddit。我想知道如何发送附加到reddit提交的文章的图像预览,或者,如果没有reddit链接,而是附加了图像,如何发送 这是我当前的代码: @client.command() @cooldown(1, 5, BucketType.user) #Command can only be used once every 5 seconds async def webdev(ctx): subreddit = reddit.subreddit

我正在使用discordpy和Praw模块访问Reddit。我想知道如何发送附加到reddit提交的文章的图像预览,或者,如果没有reddit链接,而是附加了图像,如何发送

这是我当前的代码:

@client.command()
@cooldown(1, 5, BucketType.user) #Command can only be used once every 5 seconds
async def webdev(ctx):
    subreddit = reddit.subreddit("webdev") #Subreddit name 
    all_subs = []

    hot = subreddit.hot(limit = 100)

    for submission in hot: #Iterating through the submissions in hot
        all_subs.append(submission) #Appending the submissions to the all_subs variable list

    random_sub = random.choice(all_subs) #Using the random module to randomly select one

    name = random_sub.title #Title of the submission
    body = random_sub.selftext #Body text of the submission
    link = random_sub.shortlink #Link to the submission
    url = random_sub.url #image of the submission
    img = random_sub.thumbnail #thumbnail of an exterior link (if there is one)

    em = discord.Embed(title = name) #Creating discordpy embed
    em.description = body #Setting the descriptiong to the body variable
    em.set_image(url = url) or em.set_image(url = img) #Attempting to send either the image attachment, or a link preview image
    em.add_field(name = f"Link to post:", value = link, inline= False) #Adding the submission link
    


    await ctx.send(embed = em) #Sending the embed
多谢各位