@@ -55,11 +55,9 @@ export class CorePrecondition extends AllFlowsPrecondition {
55
55
) : AllFlowsPrecondition . AsyncResult {
56
56
const required = context . permissions ?? new PermissionsBitField ( ) ;
57
57
58
- const channel = await this . fetchChannelFromInteraction ( interaction ) ;
58
+ const availablePermissions = await this . getAvailablePermissions ( interaction ) ;
59
59
60
- const permissions = await this . getPermissionsForChannel ( channel , interaction ) ;
61
-
62
- return this . sharedRun ( required , permissions , 'chat input' ) ;
60
+ return this . sharedRun ( required , availablePermissions , 'chat input' ) ;
63
61
}
64
62
65
63
public async contextMenuRun (
@@ -69,11 +67,9 @@ export class CorePrecondition extends AllFlowsPrecondition {
69
67
) : AllFlowsPrecondition . AsyncResult {
70
68
const required = context . permissions ?? new PermissionsBitField ( ) ;
71
69
72
- const channel = await this . fetchChannelFromInteraction ( interaction ) ;
73
-
74
- const permissions = await this . getPermissionsForChannel ( channel , interaction ) ;
70
+ const availablePermissions = await this . getAvailablePermissions ( interaction ) ;
75
71
76
- return this . sharedRun ( required , permissions , 'context menu' ) ;
72
+ return this . sharedRun ( required , availablePermissions , 'context menu' ) ;
77
73
}
78
74
79
75
private async getPermissionsForChannel ( channel : TextBasedChannel , messageOrInteraction : Message | BaseInteraction ) {
@@ -113,6 +109,17 @@ export class CorePrecondition extends AllFlowsPrecondition {
113
109
} ) ;
114
110
}
115
111
112
+ private async getAvailablePermissions ( interaction : ChatInputCommandInteraction | ContextMenuCommandInteraction ) {
113
+ if ( interaction . channel ) {
114
+ if ( interaction . channel . isDMBased ( ) ) return this . dmChannelPermissions ;
115
+
116
+ const channel = await this . fetchChannelFromInteraction ( interaction ) ;
117
+ return this . getPermissionsForChannel ( channel , interaction ) ;
118
+ }
119
+
120
+ return interaction . appPermissions ;
121
+ }
122
+
116
123
public static readonly readablePermissions : Record < PermissionsString , string > = {
117
124
AddReactions : 'Add Reactions' ,
118
125
Administrator : 'Administrator' ,
0 commit comments