From 23a16c3a7369d021e6b76db938831599fd14fa78 Mon Sep 17 00:00:00 2001 From: Darqam Date: Tue, 27 Nov 2018 21:41:34 +0100 Subject: [PATCH] fix(GuildChannel): add explicit channel resolve error to member edit (#2958) * Add explicit error to setting invalid voice channel * restrict to guild Co-Authored-By: Darqam * add a more explicit error and channel type check * bad tab --- src/errors/Messages.js | 1 + src/structures/GuildMember.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index 2e2ec97bb..1abdd4ca0 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -84,6 +84,7 @@ const Messages = { MESSAGE_SPLIT_MISSING: 'Message exceeds the max length and contains no split characters.', GUILD_CHANNEL_RESOLVE: 'Could not resolve channel to a guild channel.', + GUILD_VOICE_CHANNEL_RESOLVE: 'Could not resolve channel to a guild voice channel.', GUILD_CHANNEL_ORPHAN: 'Could not find a parent to this guild channel.', GUILD_OWNED: 'Guild is owned by the client.', GUILD_RESTRICTED: (state = false) => `Guild is ${state ? 'already' : 'not'} restricted.`, diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index d910117d3..a2e82d793 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -248,7 +248,11 @@ class GuildMember extends Base { */ edit(data, reason) { if (data.channel) { - data.channel_id = this.client.channels.resolve(data.channel).id; + data.channel = this.guild.channels.resolve(data.channel); + if (!data.channel || data.channel.type !== 'voice') { + throw new Error('GUILD_VOICE_CHANNEL_RESOLVE'); + } + data.channel_id = data.channel.id; data.channel = null; } if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role);