yourWaifu / sleepy-discord

C++ library for the Discord chat client. Please use Rust for new bots
https://yourWaifu.github.io/sleepy-discord/
MIT License
708 stars 93 forks source link

Issue 4 #252

Closed ghost closed 2 years ago

yourWaifu commented 2 years ago

Please understand that this library isn't designed like other Discord libraries. This library is more minimal in that it does only what's needed for your bot to keep ram and CPU usage low.

Other than that, you can keep track of the number of users in a voice channel via voice states.

void onEditVoiceState(VoiceState & state) override {
    //someone joins/leaves/moves voice channels
}

and server.voiceStates only available during onServer event with these, you can keep track of the users that are in the voice channel by updating the count as users join and leave voice channels.

yourWaifu commented 2 years ago

Voice states have user IDs, or at least it should.

yourWaifu commented 2 years ago

onServer gives you voice states, use server.voiceStates, this should tell you who on each voice channel and their voice state.

yourWaifu commented 2 years ago

I did some testing and this should work without needing to join a voice channel

    void onServer(SleepyDiscord::Server server) override {
        if (server.ID == "202917641101246465") {
            std::cout << "Targeted Server Found\n";
            for (SleepyDiscord::VoiceState& voiceState : server.voiceStates) {
                std::cout << "Voice State:\n"
                    "UserID: " << voiceState.userID.string() << "\n"
                    "ChannelID: " << voiceState.channelID.string() << '\n';

            }
        }
    }

Mind you, it's important that you have the Intents set up correctly and your bot has the SleepyDiscord::Intent::SERVERS intent set up.

client.setIntents(SleepyDiscord::Intent::SERVERS);

More info on using intents with this library here https://yourwaifu.dev/sleepy-discord/docs/connect-options#intents