diff --git a/src/index.ts b/src/index.ts index 9d1375b..162208d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,7 +25,7 @@ import { Validator } from 'jsonschema'; import { DateTime } from 'luxon'; import { Client, Collection } from 'discord.js'; import { debug, error, fatal, info, verbose } from '@utils/logger'; -import { ELoggingScope } from '@utils/types'; +import { ECommandRunIn, ELoggingScope } from '@utils/types'; import { Defaults } from '@utils/defaults'; import { walkDir } from '@utils/utils'; @@ -68,7 +68,7 @@ const client = new Client({ intents: ['GUILDS', 'GUILD_MESSAGES'], }); -client.on('message', (msg) => { +client.on('message', async (msg) => { if(!isBotReady) return; if(msg.author.bot) return; @@ -80,7 +80,18 @@ client.on('message', (msg) => { const findCommand = commands.find((com) => com.options.name === command); if(!findCommand) return; - else findCommand.run(msg, ...args); + + if((findCommand.options.runIn === ECommandRunIn.DM) && msg.channel.type !== 'dm') { + await msg.reply('You can only run this command in DMs!'); + return; + } + + if((findCommand.options.runIn === ECommandRunIn.Server) && msg.channel.type !== 'text') { + await msg.reply('You can only run this command in a server!'); + return; + } + + findCommand.run(msg, ...args); }); client.on('ready', async () => { @@ -89,7 +100,7 @@ client.on('ready', async () => { try { const files = await walkDir(`${__dirname}/commands`); - files?.forEach(async (file) => { + files?.forEach((file) => { if(file.endsWith('js')) { // eslint-disable-next-line @typescript-eslint/no-var-requires const fileCommand = require(file).default; diff --git a/src/lib/utils/types.ts b/src/lib/utils/types.ts index 0058146..183b2a9 100644 --- a/src/lib/utils/types.ts +++ b/src/lib/utils/types.ts @@ -22,11 +22,19 @@ export enum ELoggingScope { Query = 'QUERY', } +export enum ECommandRunIn { + DM, + Server, + Both, +} + // Interfaces export interface ICommandOptions { name: string; shortDescription: string; extendedDescription: string; + group: string; + runIn: ECommandRunIn; } // Type Aliases