@@ -10,6 +10,7 @@ import {
1010 SlashCommandBuilder ,
1111} from 'discord.js' ;
1212import type { CommandKit } from '../../commandkit' ;
13+ import { getConfig } from '../../config/config' ;
1314import { AsyncFunction , GenericFunction } from '../../context/async-context' ;
1415import { Logger } from '../../logger/Logger' ;
1516import type {
@@ -24,12 +25,14 @@ import { toFileURL } from '../../utils/resolve-file-url';
2425import { rewriteCommandDeclaration } from '../../utils/types-package' ;
2526import { AppCommandRunner } from '../commands/AppCommandRunner' ;
2627import { Context } from '../commands/Context' ;
28+ import { isInteractionSource } from '../commands/helpers' ;
2729import { MessageCommandParser } from '../commands/MessageCommandParser' ;
30+ import {
31+ beforeExecute as permissions_beforeExecute ,
32+ middlewareId as permissions_middlewareId ,
33+ } from '../middlewares/permissions' ;
2834import { CommandRegistrar } from '../register/CommandRegistrar' ;
2935import { Command , Middleware } from '../router' ;
30- import { getConfig } from '../../config/config' ;
31- import { beforeExecute , middlewareId } from '../middlewares/permissions' ;
32- import { isInteractionSource } from '../commands/helpers' ;
3336
3437const KNOWN_NON_HANDLER_KEYS = [
3538 'command' ,
@@ -547,6 +550,19 @@ export class AppCommandHandler {
547550 return null ;
548551 }
549552
553+ if ( source instanceof Message ) {
554+ if ( ! source . guildId ) {
555+ return null ; // command is being called in a dm
556+ }
557+
558+ if (
559+ loadedCommand . metadata ?. guilds &&
560+ ! loadedCommand . metadata . guilds . includes ( source . guildId )
561+ ) {
562+ return null ; // command is being called in a guild that is not in the metadata
563+ }
564+ }
565+
550566 // Collect all applicable middleware
551567 const middlewares : LoadedMiddleware [ ] = [ ] ;
552568
@@ -562,12 +578,12 @@ export class AppCommandHandler {
562578 middlewares . push ( {
563579 data : {
564580 // @ts -ignore
565- beforeExecute,
581+ beforeExecute : permissions_beforeExecute ,
566582 } ,
567583 middleware : {
568584 command : null ,
569585 global : true ,
570- id : middlewareId ,
586+ id : permissions_middlewareId ,
571587 name : 'permissions' ,
572588 parentPath : '' ,
573589 path : '' ,
0 commit comments