如果用户具有自定义状态,如何在Spotify中显示播放曲目?
也许我需要使用presence.activities.map
,但我不了解xd
let user = message.mentions.users.first() || message.guild.members.cache.get(args[0]) || message.member;
let convert = require('parse-ms')
let status = user.presence.activities[0];
let activity = user.presence.activities.find(activity => status.name !== "Spotify" && activity.type !== 'LISTENING')
if (activity) return message.channel.send("User isn't listening the Spotify.");
if (status !== null && status.type === "LISTENING" && status.name === "Spotify" && status.assets !== null) {
let album = status.assets.largeText,
timeStart = status.timestamps.start,
timeEnd = status.timestamps.end,
timeConvert = convert(timeEnd - timeStart);
let minutes = timeConvert.minutes < 10 ? `0${timeConvert.minutes}` : timeConvert.minutes;
let seconds = timeConvert.seconds < 10 ? `0${timeConvert.seconds}` : timeConvert.seconds;
let time = `${minutes}:${seconds}`;
let embed = new Discord.MessageEmbed()
.setColor(0x1ED768)
.setThumbnail(image)
.setDescription(`<:Spotify_iconicons:724735015895695450> ${user} listen now [\`${artist} - ${name}\`](${url})\n⠀`)
.addField(`Album: **\`${album}\`**`, `⠀`, true)
.addField(`Duration: **\`${time}\`**`, `⠀`, true)
message.channel.send(embed)
return message.delete()
答案 0 :(得分:1)
const User = client.users.cache.get("UserID"); // Getting user by ID
if (!User.presence.activities[0] || User.presence.activities[0].name !== "Spotify") return false // Checking if the user is listening to spotify.
console.log(`${User.tag} is listening to: ${User.presence.activities[0].state} - ${User.presence.activities[0].details}`) // Logging the artist and the song.
// Output --> Jakye#0000 is listening to: Sabaton - The Red Baron
要添加更多信息的状态示例:
activities: [
Activity {
name: 'Spotify',
type: 'LISTENING',
url: null,
details: 'The Red Baron',
state: 'Sabaton',
applicationID: null,
timestamps: [Object],
party: [Object],
assets: [RichPresenceAssets],
syncID: '0ePmfd8y7g4zs3E6ew7pDB',
flags: [ActivityFlags],
emoji: null,
createdTimestamp: 1593080147492
}
],