如何将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
相关产品推荐
相关产品推荐

