K
K
Kirill Bely2021-01-16 12:57:24
Node.js
Kirill Bely, 2021-01-16 12:57:24

It is necessary that the bot react only to the reactions of those who are in the voice channel. How?

The team performs the function of kicking a participant from the voice channel on a complaint. Now it works so that if a user files a complaint, then anyone who clicks on "✅" or "❌", the bot will work. I need the bot to react only to the reactions of those who are in the same voice channel with me.
Not relevant

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Israfil22, 2021-01-16
@Israfil22

1. Write the voice channel of the creator of this "vote" to a variable.

const creationChannel = message.member.voice.channel

2. One important problem must be taken into account here. The channel variable (creationChannel) will have a user cache available in the members property. The cache, respectively, is created at the time the message is received. If a user enters the channel after creating a vote, his entries will not be taken into account.
A) If the vote doesn't last too long, I guess this can be omitted and a cache is used.
Problems: The votes of users logged in after creation will not be taken into account.
B) If this approach is highly undesirable, then you will have to update the list of users asynchronously, these are relatively expensive and time consuming operations.
Problems: Each request costs about 100-200ms in a good scenario, i.e. it is undesirable to use it in the filter. An option is to create a timeout and update the cache.
C) If you don't like both options, you can make a complete list of users who voted. At the end, get the latest cache and filter it.
Be option:
const REFRESH_INTERVAL = 1000

const creationChannel = message.member.voice.channel

const refreshIntervalHandler = setInterval( async () => {
    creationChannel = await creationChannel.fetch(true)
}, REFRESH_INTERVAL)

const reactionFilter = (reaction, user) => creationChannel.members.find(member => member.user.id === user.id)

const collector = sentMessage.createReactionCollector(reactionFilter, {max : 1})

collector.on('end', () => clearInterval(refreshIntervalHandler ))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question