You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.py机器人发送消息后获取消息链接的实现咨询

获取Discord机器人发送消息的链接:可行且简单!

完全可以实现这个需求!当你的机器人通过await ctx.channel.send()发送消息后,返回的msg对象本身就携带了获取消息链接的属性,不需要额外复杂操作。

具体实现步骤

在Discord.py中,discord.Message对象有一个内置的jump_url属性,它直接对应这条消息的官方跳转链接(也就是你要的"message link")。你只需要把代码里的msg's message link替换成msg.jump_url即可。

修改后的完整代码片段

file = discord.File(f"C:/Python Data/downloads/{image}/a.gif", filename="a.gif")
embed = discord.Embed(title=f"{image}", color=ctx.author.color)
embed.set_image(url="attachment://a.gif")
embed.set_author(name=ctx.author.display_name, icon_url=ctx.author.avatar_url)
global msg
msg = await ctx.channel.send(file=file, embed=embed)
# 替换这里的msg's message link为msg.jump_url
a = [image] + [msg.jump_url]
shutil.rmtree(fr"C:/Python Data/downloads/{image}")

额外说明

  • jump_url返回的是一个字符串格式的完整URL,用户点击后会直接跳转到Discord里对应的这条消息,完全符合你的需求。
  • 这个属性在Discord.py v1.5及以上版本都支持,如果你使用的是较旧版本,建议升级到稳定版以确保兼容性。

内容的提问来源于stack exchange,提问作者thing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 09:07:45