@@ -112,7 +112,14 @@ function splitMessage(content: string): string[] {
112
112
113
113
114
114
function canSendMessage ( channel ) {
115
- // Get the bot member in the guild
115
+ console . log ( "canSendMessage" , channel ) ;
116
+ // if it is a DM channel, we can always send messages
117
+ if ( channel . type === ChannelType . DM ) {
118
+ return {
119
+ canSend : true ,
120
+ reason : null
121
+ } ;
122
+ }
116
123
const botMember = channel . guild ?. members . cache . get ( channel . client . user . id ) ;
117
124
118
125
if ( ! botMember ) {
@@ -147,18 +154,11 @@ function canSendMessage(channel) {
147
154
// Check each required permission
148
155
const missingPermissions = requiredPermissions . filter ( perm => ! permissions . has ( perm ) ) ;
149
156
150
- // Convert BigInts to strings to avoid serialization issues
151
- const missingPermNames = missingPermissions . map ( perm => {
152
- // Find the flag name by its value
153
- return Object . entries ( PermissionsBitField . Flags )
154
- . find ( ( [ _ , val ] ) => val === perm ) ?. [ 0 ] || String ( perm ) ;
155
- } ) ;
156
-
157
157
return {
158
158
canSend : missingPermissions . length === 0 ,
159
- missingPermissions : missingPermNames , // Now using string names instead of BigInts
159
+ missingPermissions : missingPermissions ,
160
160
reason : missingPermissions . length > 0
161
- ? `Missing permissions: ${ missingPermNames . join ( ', ' ) } `
161
+ ? `Missing permissions: ${ missingPermissions . map ( p => String ( p ) ) . join ( ', ' ) } `
162
162
: null
163
163
} ;
164
164
}
0 commit comments