简体   繁体   English

discord.js awaitReactions 过滤器,用于检查用户是否与 bot 处于同一频道

[英]discord.js awaitReactions filter to check if the user is in the same channel like bot

my filter doesn't work.我的过滤器不起作用。 I want, filter OUT if the bot reacts and if the channel isn't same as bot's, but it filters out all other reactions.我想,如果机器人做出反应并且频道与机器人的频道不同,则过滤掉,但它会过滤掉所有其他反应。 If other member (without bot) is in the channel and probably isn't bot, it will filter out the reaction.如果其他成员(没有机器人)在频道中并且可能不是机器人,它将过滤掉反应。

I hope you find what you need in my code, and help me:)我希望你能在我的代码中找到你需要的东西,并帮助我:)

pauseFalse(True)Reactions is array, serverQueue is JSON object, song is string pauseFalse(True)Reactions是数组,serverQueue是JSON object,song是string

var filter = (reaction, user) => {
    return pauseFalseReactions.includes(reaction.emoji.name) && message.guild.member(user.id).voice.channel == message.guild.member(botID).voice.channel && user.id != botID && user != bot.user;
};

awaitReact(message, filter, 1, Number(song.secs), pauseFalseReactions, serverQueue);

function awaitReact(message, filter, max, time, reactions, serverQueue) {
    message.awaitReactions(filter, { max: max, time: time, errors: ['time'] })
        .then(collected => {
            const reaction = collected.first();

            if (reaction.emoji.name == '⏸' && reactions.includes('⏸')) {

                Guild.findOneAndUpdate({ 
                    guildID: message.guild.id
                }, {
                    musicBotPaused: true,
                    musicBotPlaying: false
                }, function (err, result) {
                    if (err) { 
                        return console.error(err);
                    }
                });

                serverQueue.connection.dispatcher.pause();
                var newFilter = (reaction, user) => {
                    return pauseTrueReactions.includes(reaction.emoji.name) && message.guild.member(user.id).voice.channel == message.guild.member(botID).voice.channel && user.id != botID && user != bot.user;
                };
                message.reactions.removeAll().catch(error => console.error(error));
                addReactions(message, pauseTrueReactions);
                awaitReact(message, newFilter, max, (time + 250), pauseTrueReactions, serverQueue);

            } else if (reaction.emoji.name == '▶️' && reactions.includes('▶️')) {
                Guild.findOneAndUpdate({ 
                    guildID: message.guild.id
                }, {
                    musicBotPaused: false,
                    musicBotPlaying: true
                }, function (err, result) {
                    if (err) { 
                        return console.error(err);
                    }
                });

                serverQueue.connection.dispatcher.pause();
                var newFilter = (reaction, user) => {
                    return pauseFalseReactions.includes(reaction.emoji.name) && message.guild.member(user.id).voice.channel == message.guild.member(botID).voice.channel && user.id != botID && user != bot.user;
                };
                message.reactions.removeAll().catch(error => console.error(error));
                addReactions(message, pauseFalseReactions);
                awaitReact(message, newFilter, max, (time + 250), pauseFalseReactions, serverQueue);

            } else if (reaction.emoji.name == '⏭') {

                if (!serverQueue) {
                    const Embed = new Discord.MessageEmbed()
                        .setColor('#ff9745')
                        .setURL('https://discord.js.org/')
                        .setAuthor('Zigger', 'https://cdn.discordapp.com/app-icons/763859712340262972/010d590a764af0c59b999ad024cf89cb.png?size=128')
                        .setDescription('Ve frontě nic není.');
                    return message.channel.send(Embed);
                }

                message.channel.send(':fast_forward: **Přeskočeno** :thumbsup:');
                serverQueue.connection.dispatcher.end();

            } else if (reaction.emoji.name == '⏹') {

                if (serverQueue) {
                    serverQueue.connection.dispatcher.end();
                    queue.delete(message.guild.id);
                }
                message.channel.send(':stop_button: **Zastaveno!** :thumbsup:');

            }
        })
        .catch(user => {

            if (user.id != botID || user != bot.user) {
                return;
            } else {
                message.reactions.removeAll().catch(error => console.error(error));
            }
        });
}

This will always be false:这永远是错误的:

message.guild.member(user.id).voice.channel == message.guild.member(botID).voice.channel

Use采用

message.guild.member(user.id).voice.channelID == message.guild.member(botID).voice.channelID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM