Plugin
SpotifyShareCommands
Share your current Spotify track, album or artist via slash command (/track, /album, /artist)
1
/*2
* FiveCord — a Discord client mod3
* Copyright (c) 2025 FiveCord4
* SPDX-License-Identifier: GPL-3.0-or-later5
*/6
7
import { ApplicationCommandInputType, findOption, OptionalMessageOption, sendBotMessage } from "@api/Commands";8
import { Devs } from "@utils/constants";9
import { sendMessage } from "@utils/discord";10
import definePlugin from "@utils/types";11
import { Command } from "@vencord/discord-types";12
import { findByPropsLazy } from "@webpack";13
import { FluxDispatcher, MessageActions, PendingReplyStore } from "@webpack/common";14
15
interface Album {16
id: string;17
image: {18
height: number;19
width: number;20
url: string;21
};22
name: string;23
}24
25
interface Artist {26
external_urls: {27
spotify: string;28
};29
href: string;30
id: string;31
name: string;32
type: "artist" | string;33
uri: string;34
}35
36
interface Track {37
id: string | null;38
album: Album;39
artists: Artist[];40
duration: number;41
isLocal: boolean;42
name: string;43
}44
45
const Spotify = findByPropsLazy("getPlayerState");46
47
function makeCommand(name: string, formatUrl: (track: Track) => string): Command {48
return {49
name,50
description: `Share your current Spotify ${name} in chat`,51
inputType: ApplicationCommandInputType.BUILT_IN,52
options: [OptionalMessageOption],53
execute(options, { channel }) {54
const track: Track | null = Spotify.getTrack();55
if (!track) {56
return sendBotMessage(channel.id, {57
content: "You039;re not listening to any music."58
});59
}60
61
// local tracks have an id of null62
if (track.id == null) {63
return sendBotMessage(channel.id, {64
content: "Failed to find the track on spotify."65
});66
}67
68
const data = formatUrl(track);69
const message = findOption(options, "message");70
71
// Note: Due to how Discord handles commands, we need to manually create and send the message72
73
sendMessage(74
channel.id,75
{ content: message ? `${message} ${data}` : data },76
false,77
MessageActions.getSendMessageOptionsForReply(PendingReplyStore.getPendingReply(channel.id))78
).then(() => {79
FluxDispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId: channel.id });80
});81
82
}83
};84
}85
86
export default definePlugin({87
name: "SpotifyShareCommands",88
description: "Share your current Spotify track, album or artist via slash command (/track, /album, /artist)",89
tags: ["Media", "Commands"],90
authors: [Devs.katlyn],91
commands: [92
makeCommand("track", track => `https:class="ts-cmt">//open.spotify.com/track/${track.id}`),93
makeCommand("album", track => `https:class="ts-cmt">//open.spotify.com/album/${track.album.id}`),94
makeCommand("artist", track => track.artists[0].external_urls.spotify)95
]96
});97