mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
voice state fixes
This commit is contained in:
@@ -10,16 +10,15 @@ class VoiceStateUpdateHandler extends AbstractHandler {
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
if (guild) {
|
||||
// Update the state
|
||||
const oldState = guild.voiceStates.get(data.user_id);
|
||||
if (oldState) oldState._patch(data);
|
||||
else guild.voiceStates.add(data);
|
||||
|
||||
let oldState = guild.voiceStates.get(data.user_id);
|
||||
if (oldState) oldState = oldState._clone();
|
||||
const newState = guild.voiceStates.add(data);
|
||||
const member = guild.members.get(data.user_id);
|
||||
if (member) {
|
||||
if (member.user.id === client.user.id && data.channel_id) {
|
||||
client.emit('self.voiceStateUpdate', data);
|
||||
}
|
||||
client.emit(Events.VOICE_STATE_UPDATE, oldState, member.voiceState);
|
||||
client.emit(Events.VOICE_STATE_UPDATE, oldState, newState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +27,7 @@ class VoiceStateUpdateHandler extends AbstractHandler {
|
||||
/**
|
||||
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
||||
* @event Client#voiceStateUpdate
|
||||
* @param {VoiceState} oldState The voice state before the update
|
||||
* @param {?VoiceState} oldState The voice state before the update
|
||||
* @param {VoiceState} newState The voice state after the update
|
||||
*/
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ class VoiceStateStore extends DataStore {
|
||||
|
||||
add(data, cache = true) {
|
||||
const existing = this.get(data.user_id);
|
||||
if (existing) return existing;
|
||||
if (existing) return existing._patch(data);
|
||||
|
||||
const entry = new VoiceState(this.guild, data);
|
||||
if (cache) this.set(data.user_id, entry);
|
||||
|
||||
@@ -233,9 +233,7 @@ class Guild extends Base {
|
||||
if (!this.voiceStates) this.voiceStates = new VoiceStateStore(this);
|
||||
if (data.voice_states) {
|
||||
for (const voiceState of data.voice_states) {
|
||||
const existing = this.voiceStates.get(voiceState.user_id);
|
||||
if (existing) existing._patch(voiceState);
|
||||
else this.voiceStates.add(voiceState);
|
||||
this.voiceStates.add(voiceState);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ class VoiceState extends Base {
|
||||
* @type {Snowflake}
|
||||
*/
|
||||
this.channelID = data.channel_id;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -29,6 +29,10 @@ var count = 0;
|
||||
|
||||
process.on('unhandledRejection', console.log);
|
||||
|
||||
client.on('voiceStateUpdate', (a, b) => {
|
||||
console.log(a ? a.channelID : null, b ? b.channelID : null, b.member.user.username);
|
||||
});
|
||||
|
||||
client.on('message', m => {
|
||||
if (!m.guild) return;
|
||||
if (m.author.id !== '66564597481480192') return;
|
||||
|
||||
Reference in New Issue
Block a user