mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03: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);
|
const guild = client.guilds.get(data.guild_id);
|
||||||
if (guild) {
|
if (guild) {
|
||||||
// Update the state
|
// Update the state
|
||||||
const oldState = guild.voiceStates.get(data.user_id);
|
let oldState = guild.voiceStates.get(data.user_id);
|
||||||
if (oldState) oldState._patch(data);
|
if (oldState) oldState = oldState._clone();
|
||||||
else guild.voiceStates.add(data);
|
const newState = guild.voiceStates.add(data);
|
||||||
|
|
||||||
const member = guild.members.get(data.user_id);
|
const member = guild.members.get(data.user_id);
|
||||||
if (member) {
|
if (member) {
|
||||||
if (member.user.id === client.user.id && data.channel_id) {
|
if (member.user.id === client.user.id && data.channel_id) {
|
||||||
client.emit('self.voiceStateUpdate', data);
|
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.
|
* Emitted whenever a member changes voice state - e.g. joins/leaves a channel, mutes/unmutes.
|
||||||
* @event Client#voiceStateUpdate
|
* @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
|
* @param {VoiceState} newState The voice state after the update
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ class VoiceStateStore extends DataStore {
|
|||||||
|
|
||||||
add(data, cache = true) {
|
add(data, cache = true) {
|
||||||
const existing = this.get(data.user_id);
|
const existing = this.get(data.user_id);
|
||||||
if (existing) return existing;
|
if (existing) return existing._patch(data);
|
||||||
|
|
||||||
const entry = new VoiceState(this.guild, data);
|
const entry = new VoiceState(this.guild, data);
|
||||||
if (cache) this.set(data.user_id, entry);
|
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 (!this.voiceStates) this.voiceStates = new VoiceStateStore(this);
|
||||||
if (data.voice_states) {
|
if (data.voice_states) {
|
||||||
for (const voiceState of data.voice_states) {
|
for (const voiceState of data.voice_states) {
|
||||||
const existing = this.voiceStates.get(voiceState.user_id);
|
this.voiceStates.add(voiceState);
|
||||||
if (existing) existing._patch(voiceState);
|
|
||||||
else this.voiceStates.add(voiceState);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ class VoiceState extends Base {
|
|||||||
* @type {Snowflake}
|
* @type {Snowflake}
|
||||||
*/
|
*/
|
||||||
this.channelID = data.channel_id;
|
this.channelID = data.channel_id;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,6 +29,10 @@ var count = 0;
|
|||||||
|
|
||||||
process.on('unhandledRejection', console.log);
|
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 => {
|
client.on('message', m => {
|
||||||
if (!m.guild) return;
|
if (!m.guild) return;
|
||||||
if (m.author.id !== '66564597481480192') return;
|
if (m.author.id !== '66564597481480192') return;
|
||||||
|
|||||||
Reference in New Issue
Block a user