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

如何将Discord.JS获取的Spotify largeImage标识转为图片形式?

解决Discord.JS中Spotify状态largeImage转图片的问题

你控制台输出的spotify:ab67616d0000b27391eb833af3d3829f42321996是Spotify资源的标识,冒号后的字符串就是专辑封面的唯一ID。要转换成可直接访问的图片,只需用Spotify官方图片CDN地址拼接这个ID即可:

  • 基础链接格式:https://i.scdn.co/image/<专辑封面ID>
  • 替换ID后的最终链接:https://i.scdn.co/image/ab67616d0000b27391eb833af3d3829f42321996

在Discord.JS中可以通过以下代码处理:

// 先定位到用户的Spotify活动
const spotifyActivity = user.presence.activities.find(act => act.type === 'LISTENING' && act.name === 'Spotify');
if (spotifyActivity) {
  // 提取ID并拼接成图片链接
  const imageId = spotifyActivity.assets.largeImage.replace('spotify:', '');
  const imageUrl = `https://i.scdn.co/image/${imageId}`;
  console.log(imageUrl); // 输出可直接使用的图片地址
}

生成的链接可以直接用于Embed展示或浏览器访问。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 17:25:57