Add ability to kick members from VoiceChannels and remove duplicated methods (#3242)

* feat(voice): kick members from voice channels

* fix(VoiceState): improve stability in checking for client user

* feat(VoiceState): add setChannel for moving/kicking members

* update typings

* remove duplicated methods across GuildMember and VoiceState

member.setDeaf => member.voice.setDeaf
member.setMute => member.voice.setMute
member.setVoiceChannel => member.voice.setChannel
This commit is contained in:
Amish Shah
2019-05-04 16:46:42 +01:00
committed by GitHub
parent d7f8fd1ae0
commit e64773e21b
3 changed files with 21 additions and 36 deletions

View File

@@ -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<GuildMember>}
*/
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