fix(arabot): deleted channel errors

This commit is contained in:
Anthony 2024-01-27 19:38:59 +01:00
parent 502d5c5cdf
commit cf8142b86a

View File

@ -17,8 +17,8 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import type { VoiceChannel } from 'discord.js';
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks'; import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';
import { ChannelType } from 'discord.js';
export class VerifyTimeout extends ScheduledTask { export class VerifyTimeout extends ScheduledTask {
public constructor( public constructor(
@ -32,15 +32,22 @@ export class VerifyTimeout extends ScheduledTask {
// Get the guild where the user is in // Get the guild where the user is in
let channel = this.container.client.channels.cache.get( let channel = this.container.client.channels.cache.get(
payload.channelId, payload.channelId,
) as VoiceChannel | undefined; );
if (channel === undefined) { if (channel === undefined) {
channel = (await this.container.client.channels.fetch( const channelFetch = await this.container.client.channels.fetch(
payload.channelId, payload.channelId,
)) as VoiceChannel | undefined; ).catch(() => null);
if (channel === undefined) { if (channelFetch === null) {
this.container.logger.error('verifyTimeout: Channel not found!'); this.container.logger.error('verifyTimeout: Channel not found!');
return; return;
} }
channel = channelFetch;
}
if (channel.type !== ChannelType.GuildVoice) {
this.container.logger.error('verifyTimeout: Channel is not a voice channel!');
return;
} }
if (channel.members.size < 2 && channel.members.has(payload.userId)) { if (channel.members.size < 2 && channel.members.has(payload.userId)) {