From 417bfc8a18745efdd9e2890cc944c02a50a244a1 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Fri, 29 Jan 2021 18:21:06 +0200 Subject: [PATCH] get rid of the remaining calls to BaseManager#resolve to make all cache access explicit --- src/commands/info.ts | 2 +- src/commands/utilities/desc.ts | 11 +++++------ src/core/lib.ts | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/commands/info.ts b/src/commands/info.ts index a85a2e5..2de35d0 100644 --- a/src/commands/info.ts +++ b/src/commands/info.ts @@ -145,7 +145,7 @@ export default new Command({ description: "Displays info about mentioned user.", async run($: CommonLibrary): Promise { // Transforms the User object into a GuildMember object of the current guild. - const member = $.guild?.members.resolve($.args[0]) ?? (await $.guild?.members.fetch($.args[0])); + const member = await $.guild?.members.fetch($.args[0]); if (!member) return $.channel.send( diff --git a/src/commands/utilities/desc.ts b/src/commands/utilities/desc.ts index 467053c..c5e75f3 100644 --- a/src/commands/utilities/desc.ts +++ b/src/commands/utilities/desc.ts @@ -9,15 +9,14 @@ export default new Command({ if (!voiceChannel) return $.channel.send("You are not in a voice channel."); - if (!$.guild?.me?.hasPermission("MANAGE_CHANNELS")) + if (!voiceChannel.guild.me?.hasPermission("MANAGE_CHANNELS")) return $.channel.send("I am lacking the required permissions to perform this action."); if ($.args.length === 0) return $.channel.send("Please provide a new voice channel name."); - const changeVC = $.guild.channels.resolve(voiceChannel.id); - $.channel - .send(`Changed channel name from "${voiceChannel}" to "${$.args.join(" ")}".`) - /// @ts-ignore - .then(changeVC?.setName($.args.join(" "))); + const prevName = voiceChannel.name; + const newName = $.args.join(" "); + await voiceChannel.setName(newName); + await $.channel.send(`Changed channel name from "${prevName}" to "${newName}".`); } }); diff --git a/src/core/lib.ts b/src/core/lib.ts index 42852d9..73231b4 100644 --- a/src/core/lib.ts +++ b/src/core/lib.ts @@ -172,7 +172,7 @@ export function formatUTCTimestamp(now = new Date()) { } export function botHasPermission(guild: Guild | null, permission: number): boolean { - return !!(client.user && guild?.members.resolve(client.user)?.hasPermission(permission)); + return !!(guild?.me?.hasPermission(permission)); } export function updateGlobalEmoteRegistry(): void {