This is my code:
const user = message.mentions.members.first() || message.author
let spotify = user.presence.activities.filter(x => x.name == 'Spotify' && x.type == 'LISTENING')[0]
const sp = spotify.status
console.log(sp)
Is there a way to get the current time of the song on spotify and display it in seconds/minutes.
if the current song is at the 23 sec. it will display 0:23 in the console.
Discord js v13.
You can read currentTime from audio element
function logCurrentTime() {
let audioElement = document.getElementById('audio')
document.getElementById('currentTime').innerText = audioElement.currentTime
}
<body>
<button onclick="logCurrentTime()">Click to log current time</button>
<p id='currentTime'></p>
<audio id="audio" controls autoplay src="http://commondatastorage.googleapis.com/codeskulptor-assets/Epoq-Lepidoptera.ogg" />
</body>
Ref :- MediaElement
Have a look a the documentation. In this case, spotify.timestamps.start will be the time the user started the activity (as a date).
PS: The docs are your best friend! If there's anything you're ever unsure about, go here!