Features
Spotify
A PresenceResult already includes spotify: SpotifyNowPlaying | null, derived from a reported Spotify activity. You can also extract the same information from a PresenceSnapshot.
Core helper
import {
createPresenceClient,
getSpotifyNowPlaying,
getSpotifyActivity,
} from "@iconical/presencekit";
const result = await createPresenceClient().getPresence("123456789012345678");
const track = result.spotify ?? getSpotifyNowPlaying(result.presence);
if (track) {
console.log(track.song);
console.log(track.artist, track.artists);
console.log(track.album, track.albumArtUrl);
console.log(track.trackUrl, track.durationMs, track.progressMs);
}
const rawActivity = getSpotifyActivity(result.presence);
console.log(rawActivity?.details);React Spotify card
"use client";
import { usePresence } from "@iconical/presencekit/react";
import { SpotifyCard } from "@iconical/presencekit/react-ui";
export function NowPlaying({ userId }: { userId: string }) {
const { data, loading, error } = usePresence({ userId });
if (loading) return <p>Loading song…</p>;
if (error || !data?.spotify) return <p>Not listening to Spotify.</p>;
return <SpotifyCard track={data.spotify} theme={{ accent: "#ac1c23" }} />;
}Fields and accuracy
SpotifyNowPlaying exposes song, artist, artists, album, albumArtUrl, optional Spotify track ID/link, timestamp boundaries, duration, and current progress. These fields depend on Discord's reported activity and can be unavailable.
progressMs is computed at the time the payload/helper is produced; it does not automatically tick every second. For an animated progress bar, recompute from timestamps in your UI using local time and clamp to duration, or refresh from live updates.
No Spotify API token is needed to read approved Discord presence data. If Discord doesn't expose a listening activity, both getSpotifyActivity and getSpotifyNowPlaying return null.
Was this page helpful?