@@ -10,6 +10,7 @@ import {
10
10
SlashCommandBuilder ,
11
11
} from 'discord.js' ;
12
12
import type { CommandKit } from '../../commandkit' ;
13
+ import { getConfig } from '../../config/config' ;
13
14
import { AsyncFunction , GenericFunction } from '../../context/async-context' ;
14
15
import { Logger } from '../../logger/Logger' ;
15
16
import type {
@@ -24,12 +25,14 @@ import { toFileURL } from '../../utils/resolve-file-url';
24
25
import { rewriteCommandDeclaration } from '../../utils/types-package' ;
25
26
import { AppCommandRunner } from '../commands/AppCommandRunner' ;
26
27
import { Context } from '../commands/Context' ;
28
+ import { isInteractionSource } from '../commands/helpers' ;
27
29
import { MessageCommandParser } from '../commands/MessageCommandParser' ;
30
+ import {
31
+ beforeExecute as permissions_beforeExecute ,
32
+ middlewareId as permissions_middlewareId ,
33
+ } from '../middlewares/permissions' ;
28
34
import { CommandRegistrar } from '../register/CommandRegistrar' ;
29
35
import { Command , Middleware } from '../router' ;
30
- import { getConfig } from '../../config/config' ;
31
- import { beforeExecute , middlewareId } from '../middlewares/permissions' ;
32
- import { isInteractionSource } from '../commands/helpers' ;
33
36
34
37
const KNOWN_NON_HANDLER_KEYS = [
35
38
'command' ,
@@ -547,6 +550,19 @@ export class AppCommandHandler {
547
550
return null ;
548
551
}
549
552
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
+
550
566
// Collect all applicable middleware
551
567
const middlewares : LoadedMiddleware [ ] = [ ] ;
552
568
@@ -562,12 +578,12 @@ export class AppCommandHandler {
562
578
middlewares . push ( {
563
579
data : {
564
580
// @ts -ignore
565
- beforeExecute,
581
+ beforeExecute : permissions_beforeExecute ,
566
582
} ,
567
583
middleware : {
568
584
command : null ,
569
585
global : true ,
570
- id : middlewareId ,
586
+ id : permissions_middlewareId ,
571
587
name : 'permissions' ,
572
588
parentPath : '' ,
573
589
path : '' ,
0 commit comments