最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Spotify command for discord.js v12.1.1 - Stack Overflow

programmeradmin1浏览0评论
const { MessageEmbed } = require('discord.js');

module.exports = {
    config: {
        name: 'spotify',
        category: "fun",
        noalias: "No Aliases",
        description: "shows stats of the person listening",
        usage: "[no mention | mention (optional)]",
        accessableby: 'everyone'
    },
    run: async (bot, message, args) => {
        let user = message.mentions.users.first() || message.author;

        if(user.presence.game !== null && user.presence.game.type === 2 && user.presence.game.name === 'Spotify' && user.presence.game.assets !== null) {

            let trackIMG = `/${user.presence.game.assets.largeImage.slice(8)}`;
            let trackURL = `/${user.presence.game.syncID}`;
            let trackName = user.presence.game.details;
            let trackAuthor = user.presence.game.state;
            let trackAlbum = user.presence.game.assets.largeText;

            const embed = new MessageEmbed()
                .setAuthor('Spotify Track Info', '.png?v=1')
                .setColor("GREEN")
                .setThumbnail(trackIMG)
                .addField('Song Name', trackName, true)
                .addField('Album', trackAlbum, true)
                .addField('Author', trackAuthor, false)
                .addField('Listen to Track', `${trackURL}`, false)
                .setFooter(message.member.displayName, message.author.displayAvatarURL())
                .setTimestamp()

            message.channel.send(embed);
        } else {
            message.channel.send('**This user isn\'t listening to Spotify!**');
        }
    }
}

in discord version 12.1.1 it gives me error of "(node:8560) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of undefined" help me how to solve this

const { MessageEmbed } = require('discord.js');

module.exports = {
    config: {
        name: 'spotify',
        category: "fun",
        noalias: "No Aliases",
        description: "shows stats of the person listening",
        usage: "[no mention | mention (optional)]",
        accessableby: 'everyone'
    },
    run: async (bot, message, args) => {
        let user = message.mentions.users.first() || message.author;

        if(user.presence.game !== null && user.presence.game.type === 2 && user.presence.game.name === 'Spotify' && user.presence.game.assets !== null) {

            let trackIMG = `https://i.scdn.co/image/${user.presence.game.assets.largeImage.slice(8)}`;
            let trackURL = `https://open.spotify./track/${user.presence.game.syncID}`;
            let trackName = user.presence.game.details;
            let trackAuthor = user.presence.game.state;
            let trackAlbum = user.presence.game.assets.largeText;

            const embed = new MessageEmbed()
                .setAuthor('Spotify Track Info', 'https://cdn.discordapp./emojis/653135129870336031.png?v=1')
                .setColor("GREEN")
                .setThumbnail(trackIMG)
                .addField('Song Name', trackName, true)
                .addField('Album', trackAlbum, true)
                .addField('Author', trackAuthor, false)
                .addField('Listen to Track', `${trackURL}`, false)
                .setFooter(message.member.displayName, message.author.displayAvatarURL())
                .setTimestamp()

            message.channel.send(embed);
        } else {
            message.channel.send('**This user isn\'t listening to Spotify!**');
        }
    }
}

in discord version 12.1.1 it gives me error of "(node:8560) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'type' of undefined" help me how to solve this

Share Improve this question edited Apr 2, 2020 at 11:15 Lauren Yim 14.2k2 gold badges37 silver badges66 bronze badges asked Apr 1, 2020 at 15:32 FirezFirez 931 gold badge3 silver badges8 bronze badges 1
  • changed the code hastebin./eqejuhiquc.js -- spotify updated code, but it shows that user is not listening on spotify, though i am. also no errors. – Firez Commented Apr 3, 2020 at 4:55
Add a ment  | 

2 Answers 2

Reset to default 2

in fact since discord.js v12 game has been removed from presence use:

user.presence.activities

well i have made a better mand which not only checks if the user is playing spotify or not but also games and whatever else the user is playing along with custom status go here to get it ---

https://github./FirezzzZ/1SHOT-Bot/tree/glitch

发布评论

评论列表(0)

  1. 暂无评论