Spotify状态更新Discord Bot问题

时间:2018-10-05 00:49:07

标签: node.js discord discord.js

对于不和谐的bot,我的状态更新脚本有点麻烦。

我的代码从一开始就可以正常工作,为应用程序用户赋予角色并发布他们正在播放的内容,但是当用户退出应用程序时,代码的最后一部分永远不会触发并删除角色:

client.on('presenceUpdate', (oldMember, newMember) => {
if (oldMember.user.bot || newMember.user.bot) return;
let guild = newMember.guild;
let playRole = guild.roles.find("name", "Playing Spotify");
if(!playRole) return;
if (newMember.presence.game != null && newMember.guild.id === config.guild) {

    if (newMember.presence.game.name === ('Spotify')) {

        const logChannel = client.channels.find(channel => channel.name === config.spotify)
        //count++;
        newMember.addRole(playRole).catch(console.error);
        client.channels.find(x => x.id === "493837894499434536").setTopic("[AUTOMATED SYSTEM] \nCurrent Users Listening: " + playRole.members.size);


        console.log("[DEBUG]:Channel Topic Updated to: [Count Up] Current Users Listening: " + playRole.members.size)
        console.log("[DEBUG - Secondary-Check]: Channel Topic Updated to: [Count Up] Current Users Listening: " + playRole.members.size)


        var trackImg = newMember.presence.game.assets.largeImageURL;
        var trackUrl = `https://open.spotify.com/track/${newMember.presence.game.syncID}`;
        var trackName = newMember.presence.game.details;
        var trackAlbum = newMember.presence.game.assets.largeText;
        var trackAuthor = newMember.presence.game.state;


        let embed = new Discord.RichEmbed()
            .setTitle(`${newMember.displayName}#${newMember.user.discriminator} Listening to Spotify`)
            .setColor('FF0000')
            .setThumbnail(trackImg)
            .addField("Song Name", `${trackName}`, true)
            .addField("Album", `${trackAlbum}`, true)
            .addField("Author", `${trackAuthor}`, true)
            .addField('Listen to this track here:', `[Open Spotify](${trackUrl})`, true)

            .setFooter(`Listening to Spotify`)

        logChannel.send(embed)
    } else {
        if(!newMember.user.presence.game && newMember.roles.has(playRole.id))

       console.log("[DEBUG]: Channel Topic Updated to: [Count Down] Current Users Listening: " + playRole.members.size)
       client.channels.find(x => x.id === "493837894499434536").setTopic("[AUTOMATED SYSTEM] \nCurrent Users Listening To Spotify: " + playRole.members.size);
       console.log("[DEBUG - Secondary-Check]: Channel Topic Updated to: [Count Down] Current Users Listening: " + playRole.members.size)

    }
}
});

我花了很多时间来开发这段代码,但是我只停留在一个问题上,并且我尝试了各种可能使其工作,调试和调试,

感谢您的帮助。

0 个答案:

没有答案