Emitter Not Firing

I'm currently using the voiceStateUpdate event emitter, and I believe I've come across a problem. When a user leaves the voice channel, a new state (event) gets emitted. However, when a user leaves the voice channel while streaming, a new state (event) does not get emitted. Just to clarify, it seems to be registering starting a stream and ending a stream fine. Just the problem above ^^ Is this a problem with the discord api, discord.js or possibly even my code?
33 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
SpecialSauce
SpecialSauce11mo ago
Are you positive that the member is cached before leaving? If not you may need the guildmember partial.
victorr
victorr11mo ago
How can I check this?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
Still doesn't seem to be firing, here is my code just in case:
const botClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildInvites,
],
partials: [
Partials.Channel,
Partials.GuildMember
]
});
const botClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildInvites,
],
partials: [
Partials.Channel,
Partials.GuildMember
]
});
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
botClient.on('voiceStateUpdate', async (oldState, newState) => {
console.log("Old State:", oldState, "New State:", newState)
})
botClient.on('voiceStateUpdate', async (oldState, newState) => {
console.log("Old State:", oldState, "New State:", newState)
})
There's a bunch of stuff in-between but I made sure to test the firing outside of any interfering code blocks.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
In all honesty this was a template, but yes it does seem to be exporting the client.
const botClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildInvites,
],
partials: [
Partials.Channel,
Partials.GuildMember
]
});

exports.rootPath = dirPath;
exports.client = botClient;
exports.guildCooldownDB = new QuickDB({
filePath: `${dirPath}/guildCooldownDB.sqlite`
});
exports.globalCooldownDB = new QuickDB({
filePath: `${dirPath}/globalCooldownDB.sqlite`
});
exports.channelCooldownDB = new QuickDB({
filePath: `${dirPath}/channelCooldownDB.sqlite`
});

botClient.messageCommands = new Collection();
botClient.messageCommandsAliases = new Collection();
botClient.events = new Collection();
botClient.buttonCommands = new Collection();
botClient.selectMenus = new Collection();
botClient.modalForms = new Collection();
botClient.slashCommands = new Collection();
const botClient = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildInvites,
],
partials: [
Partials.Channel,
Partials.GuildMember
]
});

exports.rootPath = dirPath;
exports.client = botClient;
exports.guildCooldownDB = new QuickDB({
filePath: `${dirPath}/guildCooldownDB.sqlite`
});
exports.globalCooldownDB = new QuickDB({
filePath: `${dirPath}/globalCooldownDB.sqlite`
});
exports.channelCooldownDB = new QuickDB({
filePath: `${dirPath}/channelCooldownDB.sqlite`
});

botClient.messageCommands = new Collection();
botClient.messageCommandsAliases = new Collection();
botClient.events = new Collection();
botClient.buttonCommands = new Collection();
botClient.selectMenus = new Collection();
botClient.modalForms = new Collection();
botClient.slashCommands = new Collection();
d.js docs
d.js docs11mo ago
guide Creating Your Bot: Event handling read more
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
That is already present
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
The handler didn't include a voiceStateUpdate event, and tbh I wasn't 100% sure how to adapt it I'll take a look now, and see if I can get it to work
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
Sure
victorr
victorr11mo ago
It's in a few files, would you like to see them all?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
const commandOptionsProcessor = require("../Structures/CommandOptions/Processor");
module.exports = {
name: 'interactionCreate',
run: async (interaction, client) => {
if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
const slashCommand = client.slashCommands.get(interaction.commandName);
if (!slashCommand) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, slashCommand, true, "SlashCommand");
if (authenticatedCMDOptions) return await slashCommand.run(client, interaction);
}
else if (interaction.isAnySelectMenu()) {
const selectMenuCommand = client.selectMenus.get(interaction.values[0]) ?? client.selectMenus.get(interaction.customId);
if (!selectMenuCommand) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, selectMenuCommand, true, "SelectMenu");
if (authenticatedCMDOptions) return await selectMenuCommand.run(client, interaction);
}
else if (interaction.isButton()) {
const buttonInteraction = client.buttonCommands.get(interaction.customId);
if (!buttonInteraction) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, buttonInteraction, true, "Button");
if (authenticatedCMDOptions) return await buttonInteraction.run(client, interaction);
}
else if (interaction.isModalSubmit()) {
const modalInteraction = client.modalForms.get(interaction.customId);
if (!modalInteraction) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, modalInteraction, true, "ModalForm");
if (authenticatedCMDOptions) return await modalInteraction.run(client, interaction);
}
}
};
const commandOptionsProcessor = require("../Structures/CommandOptions/Processor");
module.exports = {
name: 'interactionCreate',
run: async (interaction, client) => {
if (interaction.isChatInputCommand() || interaction.isContextMenuCommand()) {
const slashCommand = client.slashCommands.get(interaction.commandName);
if (!slashCommand) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, slashCommand, true, "SlashCommand");
if (authenticatedCMDOptions) return await slashCommand.run(client, interaction);
}
else if (interaction.isAnySelectMenu()) {
const selectMenuCommand = client.selectMenus.get(interaction.values[0]) ?? client.selectMenus.get(interaction.customId);
if (!selectMenuCommand) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, selectMenuCommand, true, "SelectMenu");
if (authenticatedCMDOptions) return await selectMenuCommand.run(client, interaction);
}
else if (interaction.isButton()) {
const buttonInteraction = client.buttonCommands.get(interaction.customId);
if (!buttonInteraction) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, buttonInteraction, true, "Button");
if (authenticatedCMDOptions) return await buttonInteraction.run(client, interaction);
}
else if (interaction.isModalSubmit()) {
const modalInteraction = client.modalForms.get(interaction.customId);
if (!modalInteraction) return;
const authenticatedCMDOptions = await commandOptionsProcessor(client, interaction, modalInteraction, true, "ModalForm");
if (authenticatedCMDOptions) return await modalInteraction.run(client, interaction);
}
}
};
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
Mhm Ah so I just use voiceStateUpdate?
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
Ah right I see
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
Uh, where can I check this? I'm not 100% sure
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
I think it should be this:
const { statSync } = require("node:fs");
const directorySearch = require("node-recursive-directory");
module.exports = async(client, rootPath) => {
const clientEventsFiles = await directorySearch(`${rootPath}/Src/Events`);
clientEventsFiles.forEach(eventFile => {
if (statSync(eventFile).isDirectory()) return;
const clientEvent = require(eventFile);
if (clientEvent.ignore || !clientEvent.name || !clientEvent.run) return;

client.events.set(clientEvent.name, clientEvent);
if (clientEvent.customEvent) return clientEvent.run(client, rootPath);

if (clientEvent.runOnce) client.once(clientEvent.name, (...args) => clientEvent.run(...args, client, rootPath));
else client.on(clientEvent.name, (...args) => clientEvent.run(...args, client, rootPath));
});
};
const { statSync } = require("node:fs");
const directorySearch = require("node-recursive-directory");
module.exports = async(client, rootPath) => {
const clientEventsFiles = await directorySearch(`${rootPath}/Src/Events`);
clientEventsFiles.forEach(eventFile => {
if (statSync(eventFile).isDirectory()) return;
const clientEvent = require(eventFile);
if (clientEvent.ignore || !clientEvent.name || !clientEvent.run) return;

client.events.set(clientEvent.name, clientEvent);
if (clientEvent.customEvent) return clientEvent.run(client, rootPath);

if (clientEvent.runOnce) client.once(clientEvent.name, (...args) => clientEvent.run(...args, client, rootPath));
else client.on(clientEvent.name, (...args) => clientEvent.run(...args, client, rootPath));
});
};
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs11mo ago
class Client (extends BaseClient) The main hub for interacting with the Discord API, and the starting point for any bot.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
Yep, seems to be working now. Thank you very much, you're a life saver.
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
victorr
victorr11mo ago
🙏