#voiceState

14 messages · Page 1 of 1 (latest)

sour narwhalBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
echo sparrowBOT
#

event (event) Client#voiceStateUpdate
Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.

long crystal
#

@broken musk okay thanks Is it possible to know how long the user has been in voice?

broken musk
#

Not in the event, you would need to record the times the join and leave events fire and track that yourself

long crystal
#

I detect when a user logs out, but not when they log into a voice room

pearl aurora
long crystal
# pearl aurora What parameters do you actually pass when calling that?
    const member = newState.member;
    const guild = newState.guild;

    const oldChannel = oldState.channel ? oldState.channel.name : 'Aucun';
    const newChannel = newState.channel ? newState.channel.name : 'Aucun';

    switch (true) {

        case !oldState.channel && newState.channel:
            console.log(`${member.user.tag} a rejoint le salon vocal`);
            break;

        case oldState.channel && !newState.channel:
            console.log(`${member.user.tag} a quitté le salon vocal ${oldChannel}`);
            break;

        case oldState.mute !== newState.mute:
            if (newState.mute) {
                console.log(`${member.user.tag} est désormais mute dans ${newChannel}`);
            } else {
                console.log(`${member.user.tag} n'est plus mute dans ${newChannel}`);
            }
            break;

        case oldState.deaf !== newState.deaf:
            if (newState.deaf) {
                console.log(`${member.user.tag} est désormais en sourdine dans ${newChannel}`);
            } else {
                if (newState.mute) { 
                    console.log(`${member.user.tag} n'est plus sourdine dans ${newChannel}`);
                }
            }
            break;

        case oldState.streaming !== newState.streaming:
            if (newState.streaming) {
                console.log(`${member.user.tag} a commencé à diffuser en streaming dans ${newChannel}`);
            } else {
                console.log(`${member.user.tag} a arrêté de diffuser en streaming dans ${newChannel}`);
            }
            break;

        case oldState.selfVideo !== newState.selfVideo:
            if (newState.selfVideo) {
                console.log(`${member.user.tag} a activé sa caméra dans ${newChannel}`);
            } else {
                console.log(`${member.user.tag} a désactivé sa caméra dans ${newChannel}`);
            }
            break;

        default:
            break;
    }
};
#
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const config = require('./src/config.json');
const commandHandler = require('./handler');

const client = new Client({
    intents: [ 
        GatewayIntentBits.Guilds,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildIntegrations,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildVoiceStates,
        
    ],
    partials: [
        Partials.Message,
        Partials.Channel,
        Partials.GuildMember,
        Partials.Reaction,
        Partials.GuildScheduledEvent,
        Partials.User,
        Partials.ThreadMember,
    ]
});

commandHandler(client);

client.on('ready', async () => {
    const readyEvent = require('./events/client/ready.js');
    await readyEvent.execute(client);
});

client.on('messageCreate', async (message) => {
    if (!client.db) return;
    const messageCreateEvent = require('./databaseHandlers/MessageUserScore.js')
    await messageCreateEvent.execute(client, message);
});

client.on('voiceStateUpdate', (oldState, newState) => {
    if (!client.db) return;
    const voiceStateUpdateEvent = require('./databaseHandlers/VocalUserScore.js');
    voiceStateUpdateEvent(client, oldState, newState);
});

client.login(config.token);```
pearl aurora
#

Apart from that abomination of a switch statement that looks correct. What exactly happens?

long crystal