From 57887b9aeaca69240d702cfb6d87ccaacdca8f7f Mon Sep 17 00:00:00 2001 From: naseif Date: Wed, 1 Sep 2021 15:28:28 +0000 Subject: [PATCH] [Fix] Added error handling in case a channel with the given id does not exist, added automatic region option --- commands/admin/region.js | 3 ++- commands/admin/regionById.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/commands/admin/region.js b/commands/admin/region.js index 9627524..71c3ccf 100644 --- a/commands/admin/region.js +++ b/commands/admin/region.js @@ -13,6 +13,7 @@ module.exports = { .setName("region") .setDescription("select the region you wish to set") .setRequired(true) + .addChoice("Automatic", "null") .addChoice("Brazil", "brazil") .addChoice("Europe", "europe") .addChoice("Hong Kong", "hongkong") @@ -56,7 +57,7 @@ module.exports = { ], }); } - let currentRtc = voiceChannel.rtcRegion; + try { await voiceChannel.setRTCRegion(region); await interaction.followUp({ diff --git a/commands/admin/regionById.js b/commands/admin/regionById.js index be4705a..765d7ce 100644 --- a/commands/admin/regionById.js +++ b/commands/admin/regionById.js @@ -17,6 +17,7 @@ module.exports = { .setName("region") .setDescription("select the region you wish to set") .setRequired(true) + .addChoice("Automatic", "null") .addChoice("Brazil", "brazil") .addChoice("Europe", "europe") .addChoice("Hong Kong", "hongkong") @@ -36,7 +37,18 @@ module.exports = { const vcId = interaction.options.getString("id"); const region = interaction.options.getString("region"); const voiceChannel = await interaction.guild.channels.cache.get(vcId); - let currentRtc = voiceChannel.rtcRegion; + let currentRtc = voiceChannel.rtcRegion || "Default"; + + if (!voiceChannel) { + return await interaction.followUp({ + embeds: [ + embedMessage( + "#9dcc37", + `A voice channel with this id does not exist!` + ), + ], + }); + } if ( !interaction.member.permissions.has([Permissions.FLAGS.ADMINISTRATOR]) ||