首页 > 解决方案 > 在discord py的嵌入消息中发送带有用户标签的随机gif

问题描述

我试图在嵌入消息中发送带有用户提及的随机 gif,用户标签很好,但 gif 不会显示在嵌入消息中。这是消息的屏幕截图

也是命令的代码

@client.command()
async def slap(ctx, user: discord.Member):
    randomgifs = [
    discord.Embed(title = "", description = f'{ctx.author.mention} has slapped {user.mention}\n\nhttps://i.imgur.com/8KfHd8m.gif', color = ctx.author.color), 
    discord.Embed(title = "", description = f'{ctx.author.mention} has slapped {user.mention}\n\nhttps://i.imgur.com/AAUukQd.gif', color = ctx.author.color),
    discord.Embed(title = "", description = f'{ctx.author.mention} has slapped {user.mention}\n\nhttps://i.imgur.com/ZDiDDdc.gif', color = ctx.author.color),
    discord.Embed(title = "", description = f'{ctx.author.mention} has slapped {user.mention}\n\nhttps://i.imgur.com/28BGRwI.gif', color = ctx.author.color),
    discord.Embed(title = "", description = f'{ctx.author.mention} has slapped {user.mention}\n\nhttps://i.imgur.com/HqHljrw.gif', color = ctx.author.color)]
    randomitem = random.choice(randomgifs)
    await ctx.send(embed=randomitem)

我已经看到了很多与此类似的问题,但是对于随机消息没有一个答案,并且当我在这些问题中使用它们的固定代码时,该命令不起作用。谢谢你。

标签: discord.py

解决方案


只是将链接放在嵌入的描述中不会呈现它。您需要将其设置为图像

@client.command()
async def slap(ctx, user: discord.Member):
    randomgifs = [
        "https://i.imgur.com/8KfHd8m.gif",
        "https://i.imgur.com/AAUukQd.gif",
        "https://i.imgur.com/ZDiDDdc.gif",
        "https://i.imgur.com/28BGRwI.gif",
        "https://i.imgur.com/HqHljrw.gif"
    ]
    
    embed = discord.Embed(
        title = "",
        description = f"{ctx.author.mention} has slapped {user.mention}",
        color = ctx.author.color
    )

    randomgif = random.choice(randomgifs)
    embed.set_image(url = randomgif)
    await ctx.send(embed = embed)

推荐阅读