diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 567c27e8a..697f8e061 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -254,7 +254,8 @@ class GuildMember extends Base { * @property {Collection|RoleResolvable[]} [roles] The roles or role IDs to apply * @property {boolean} [mute] Whether or not the member should be muted * @property {boolean} [deaf] Whether or not the member should be deafened - * @property {ChannelResolvable} [channel] Channel to move member to (if they are connected to voice) + * @property {ChannelResolvable|null} [channel] Channel to move member to (if they are connected to voice), or `null` + * if you want to kick them from voice */ /** @@ -270,8 +271,10 @@ class GuildMember extends Base { throw new Error('GUILD_VOICE_CHANNEL_RESOLVE'); } data.channel_id = data.channel.id; - data.channel = null; + } else if (data.channel === null) { + data.channel_id = null; } + data.channel = undefined; if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role); let endpoint = this.client.api.guilds(this.guild.id); if (this.user.id === this.client.user.id) { @@ -289,35 +292,6 @@ class GuildMember extends Base { return clone; } - /** - * Mutes/unmutes this member. - * @param {boolean} mute Whether or not the member should be muted - * @param {string} [reason] Reason for muting or unmuting - * @returns {Promise} - */ - setMute(mute, reason) { - return this.edit({ mute }, reason); - } - - /** - * Deafens/undeafens this member. - * @param {boolean} deaf Whether or not the member should be deafened - * @param {string} [reason] Reason for deafening or undeafening - * @returns {Promise} - */ - setDeaf(deaf, reason) { - return this.edit({ deaf }, reason); - } - - /** - * Moves this member to the given channel. - * @param {ChannelResolvable} channel The channel to move the member to - * @returns {Promise} - */ - setVoiceChannel(channel) { - return this.edit({ channel }); - } - /** * Sets the nickname for this member. * @param {string} nick The nickname for the guild member diff --git a/src/structures/VoiceState.js b/src/structures/VoiceState.js index 165aa7b66..e2cb2ab99 100644 --- a/src/structures/VoiceState.js +++ b/src/structures/VoiceState.js @@ -85,7 +85,7 @@ class VoiceState extends Base { * @readonly */ get connection() { - if (browser || this.id !== this.guild.me.id) return null; + if (browser || this.id !== this.client.user.id) return null; return this.client.voice.connections.get(this.guild.id) || null; } @@ -139,6 +139,19 @@ class VoiceState extends Base { return this.member ? this.member.edit({ deaf }, reason) : Promise.reject(new Error('VOICE_STATE_UNCACHED_MEMBER')); } + /** + * Moves the member to a different channel, or kick them from the one they're in. + * @param {ChannelResolvable|null} [channel] Channel to move the member to, or `null` if you want to kick them from + * voice + * @param {string} [reason] Reason for moving member to another channel or kicking + * @returns {Promise} + */ + setChannel(channel, reason) { + return this.member ? + this.member.edit({ channel }, reason) : + Promise.reject(new Error('VOICE_STATE_UNCACHED_MEMBER')); + } + /** * Self-mutes/unmutes the bot for this voice state. * @param {boolean} mute Whether or not the bot should be self-muted diff --git a/typings/index.d.ts b/typings/index.d.ts index 215abc3ae..726f07428 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -591,10 +591,7 @@ declare module 'discord.js' { public hasPermission(permission: PermissionResolvable, options?: { checkAdmin?: boolean; checkOwner?: boolean }): boolean; public kick(reason?: string): Promise; public permissionsIn(channel: ChannelResolvable): Readonly; - public setDeaf(deaf: boolean, reason?: string): Promise; - public setMute(mute: boolean, reason?: string): Promise; public setNickname(nickname: string, reason?: string): Promise; - public setVoiceChannel(voiceChannel: ChannelResolvable): Promise; public toJSON(): object; public toString(): string; } @@ -1287,6 +1284,7 @@ declare module 'discord.js' { public setDeaf(deaf: boolean, reason?: string): Promise; public setMute(mute: boolean, reason?: string): Promise; + public setChannel(channel: ChannelResolvable | null, reason?: string): Promise; public setSelfDeaf(deaf: boolean): Promise; public setSelfMute(mute: boolean): Promise; } @@ -1927,7 +1925,7 @@ declare module 'discord.js' { roles?: Collection | RoleResolvable[]; mute?: boolean; deaf?: boolean; - channel?: ChannelResolvable; + channel?: ChannelResolvable | null; } type GuildMemberResolvable = GuildMember | UserResolvable;