Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

voice_state_update issue #902

Closed
NickTsaizer opened this issue Jul 5, 2020 · 4 comments
Closed

voice_state_update issue #902

NickTsaizer opened this issue Jul 5, 2020 · 4 comments
Labels
client Related to the `client` module. question A question about Serenity.

Comments

@NickTsaizer
Copy link

Good day!
I found an issue with "voice_state_update". It needs 4 arguments (and it works ok with them), but I can see those warnings:

image

Also i cant find where i can get voice chat user counter.
image
plz help me.

And sorry my english, im just stupid.

@arqunis arqunis added client Related to the `client` module. question A question about Serenity. labels Jul 5, 2020
@arqunis
Copy link
Member

arqunis commented Jul 5, 2020

This is not an issue, it's intentional. Based on whether you have the cache feature enabled, the voice_state_update handler may either have three or four parameters. Discord does not provide the previous state of data, so we must cache most things if we want to pass on this old version of the data to the consumers of the library. If the cache is disabled, we can't do that.

If your code compiles and works with the four parameters, then don't mind this warning. It's likely your IDE is unable to recognize the feature flag and apply it.

Also i cant find where i can get voice chat user counter.

Would you mind clarifying? Do you mean how many users are in a voice channel?

@NickTsaizer
Copy link
Author

NickTsaizer commented Jul 5, 2020

Yep. I just need to check how many users connected to voice channel when one of them left. I can get channel object, but it has not .users or .user_count() or something like that.

@arqunis
Copy link
Member

arqunis commented Jul 5, 2020

There isn't a dedicated function for this task, but you can implement one yourself. The library keeps track of all voice states in a guild. You can filter these based on the channel of your interest to get the amount of users in the channel.

fn user_count(guild: &Guild, channel_id: ChannelId) -> usize {
    guild
        .voice_states
        .values()
        .filter(|state| { 
            match state.channel_id {
                Some(c) => c == channel_id,
                None => false,
            }
        })
        .count()
}

@NickTsaizer
Copy link
Author

Ok, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Related to the `client` module. question A question about Serenity.
Projects
None yet
Development

No branches or pull requests

2 participants