From a1924e411c5cb2a73fc13528c50cccfb1e826b06 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 20 Jul 2022 12:33:06 +0200 Subject: [PATCH] update with eslint rules --- src/commands/loader.ts | 4 ++-- src/events/loader.ts | 2 +- src/index.ts | 8 ++++---- src/utils/client.ts | 18 +++++++++++------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/commands/loader.ts b/src/commands/loader.ts index 38c9f4f..2330326 100644 --- a/src/commands/loader.ts +++ b/src/commands/loader.ts @@ -4,7 +4,7 @@ import { Client } from 'discord.js'; import { readdir } from 'fs/promises'; export default async (client: Client) => { - const rest = new REST({ version: '9' }).setToken(client.token!); + const rest = new REST({ version: '9' }).setToken(client.token ?? ''); const command_categories = (await readdir('./src/commands')) .filter(element => !element.endsWith('.js')); @@ -32,7 +32,7 @@ export default async (client: Client) => { ) ).flat(2); - return await rest.put(Routes.applicationCommands(client.user!.id), { + return await rest.put(Routes.applicationCommands(client.user?.id ?? ''), { body: commands, }); }; diff --git a/src/events/loader.ts b/src/events/loader.ts index d4e4a60..ec6abd3 100644 --- a/src/events/loader.ts +++ b/src/events/loader.ts @@ -17,7 +17,7 @@ export default async (client: Client) => { ); // Remove .js - let event_type_ext = event_file.split('.'); + const event_type_ext = event_file.split('.'); if (event_type_ext.pop() !== 'js') { throw `Unknown file in ${event_category}: ${event_file}`; } diff --git a/src/index.ts b/src/index.ts index 14d6c51..0825837 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,7 @@ const run = async () => { .then(async client => { console.log('Client ✅'); await loadEvents(client) - .then(_ => console.log('Events ✅')) + .then(() => console.log('Events ✅')) .catch(() => { throw 'Events ❌'; }); @@ -23,14 +23,14 @@ const run = async () => { await client.login(client.config.token_discord); await loadCommands(client) - .then(_ => console.log('Commands ✅')) + .then(() => console.log('Commands ✅')) .catch(() => { throw 'Commands ❌'; }); - console.log(`Botanique "${client.user!.username}" ${client.config.version} started!`); + console.log(`Botanique "${client.user?.username}" ${client.config.version} started!`); }) - .catch(_ => { + .catch(() => { throw 'Client ❌'; }); }; diff --git a/src/utils/client.ts b/src/utils/client.ts index e11fde2..53069fa 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -4,16 +4,20 @@ import { SlashCommandBuilder } from '@discordjs/builders'; const { version } = JSON.parse(readFileSync('./package.json').toString()); -declare module "discord.js" { +declare module 'discord.js' { + // eslint-disable-next-line no-shadow export interface Client { config: { - version: any, - token_discord: any + version: string, + token_discord: string | undefined }, - commands: Collection any - }> + commands: Collection< + string, + { + data: SlashCommandBuilder, + interaction: (interaction: CommandInteraction, client: Client) => unknown + } + > } }