Keymax
Keymax
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
No description
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
I don't know, but the first option didn't work for me
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
<a:sweetpiano_happy:1051864341835698276> I finally understood the incorrectly described import of events, old
client.on(eventName, async (arg) => {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, ...arg);
}
});
client.on(eventName, async (arg) => {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, ...arg);
}
});
that's how it should be new
client.on(eventName, async function() {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, ...arguments);
}
});
client.on(eventName, async function() {
for (const eventFile of eventFiles) {
const eventFunction = require(eventFile);
await eventFunction(client, ...arguments);
}
});
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
Use arrays in both cases. You can pass single arguments as an array with one element. This ensures consistency but might require additional handling inside the function.
// Single argument
const arg1 = [singleValue];
await eventFunction(client, ...arg1);

// Multiple arguments
const arg2 = [value1, value2, value3];
await eventFunction(client, ...arg2);
// Single argument
const arg1 = [singleValue];
await eventFunction(client, ...arg1);

// Multiple arguments
const arg2 = [value1, value2, value3];
await eventFunction(client, ...arg2);
Inside eventFunction, you would handle the arguments as an array:
function eventFunction(client, ...args) {
// args is an array
}
function eventFunction(client, ...args) {
// args is an array
}
Check the type of arg before calling. If arg is an array, you can use the spread syntax; otherwise, pass it as is.
if (Array.isArray(arg)) {
await eventFunction(client, ...arg);
} else {
await eventFunction(client, arg);
}
if (Array.isArray(arg)) {
await eventFunction(client, ...arg);
} else {
await eventFunction(client, arg);
}
Modify the structure of eventFunction to always accept an array. This way, you won't have to worry about the number of arguments you're passing.
async function eventFunction(client, args) {
// args is always an array
}

// When calling
await eventFunction(client, [singleArg]); // One argument
await eventFunction(client, [arg1, arg2, arg3]); // Multiple arguments
async function eventFunction(client, args) {
// args is always an array
}

// When calling
await eventFunction(client, [singleArg]); // One argument
await eventFunction(client, [arg1, arg2, arg3]); // Multiple arguments
Depending on your specific scenario, one of these options might be more preferable. Choose the one that best fits your requirements and coding style.
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
I didn't really understand, do I need to declare in this way?
eventFunction(client, ...arg);
eventFunction(client, ...arg);
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
Okay, I figured it out, because I tried to import this event as a separate file. However, if I prescribe directly from index.js works everything out fine
[INDEX] Old Channel ID: null New Channel ID: 883322478036938792
[VOICEXP.js] Old Channel ID: null New Channel ID: null
[INDEX] Old Channel ID: null New Channel ID: 883322478036938792
[VOICEXP.js] Old Channel ID: null New Channel ID: null
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
I just thought if I join a voice chat, then:
oldState.channel = null and newState.channel = 12313213
oldState.channel = null and newState.channel = 12313213
But for some reason these values are always the same
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
I specified the variables correctly:
console.log(`[JOIN] Old Channel ID: ${oldState.channelId} New Channel ID: ${newState.channelId}`)
console.log(`[Deaf] Old Channel ID: ${oldState.selfDeaf} New Channel ID: ${newState.selfDeaf}`)
console.log(`[Mute] Old Channel ID: ${oldState.selfMute} New Channel ID: ${newState.selfMute}`)
console.log(`[JOIN] Old Channel ID: ${oldState.channelId} New Channel ID: ${newState.channelId}`)
console.log(`[Deaf] Old Channel ID: ${oldState.selfDeaf} New Channel ID: ${newState.selfDeaf}`)
console.log(`[Mute] Old Channel ID: ${oldState.selfMute} New Channel ID: ${newState.selfMute}`)
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
Yes, I understand, but even if I output these values in the console, they are still always the same: Mute and unmute:
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: false New Channel ID: false
[Mute] Old Channel ID: false New Channel ID: false
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: false New Channel ID: false
[Mute] Old Channel ID: true New Channel ID: true
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: false New Channel ID: false
[Mute] Old Channel ID: false New Channel ID: false
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: false New Channel ID: false
[Mute] Old Channel ID: true New Channel ID: true
Deaf and undeaf
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: false New Channel ID: false
[Mute] Old Channel ID: false New Channel ID: false
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: true New Channel ID: true
[Mute] Old Channel ID: true New Channel ID: true
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: false New Channel ID: false
[Mute] Old Channel ID: false New Channel ID: false
[JOIN] Old Channel ID: 883322478036938792 New Channel ID: 883322478036938792
[Deaf] Old Channel ID: true New Channel ID: true
[Mute] Old Channel ID: true New Channel ID: true
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
I have the same value displayed in the console,
[JOIN] <#883322478036938792> and <#883322478036938792>
[JOIN] null and null
[JOIN] <#883322478036938792> and <#883322478036938792>
[JOIN] null and null
do I not understand something? I want to check the current state of the user and compare it, but it gives the same thing. How do I understand what is happening to a person right now
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
💗
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
Thanks for the help, I really added to EventHandler.js 1 more argument for events and everything started to work stably. Thanks a lot ❤️
await eventFunction(client, arg, arg);
await eventFunction(client, arg, arg);
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
No description
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
I'm not sure, but at least the first WORK output, which is declared at the very beginning of the code, works.
console.log(`WORK`);
console.log(`WORK`);
But the rest are gone
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
Just "giveUserXp.js" is working fine
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
No description
46 replies
DIAdiscord.js - Imagine an app
Created by Keymax on 10/16/2023 in #djs-questions
How to correctly make a VoiceState event using eventHandler
Here is my other MessageCreate event, it works fine
46 replies