File tree Expand file tree Collapse file tree 4 files changed +28
-5
lines changed Expand file tree Collapse file tree 4 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -90,3 +90,11 @@ Defined in [discord.js](https://discord.js.org/#/docs/discord.js/main/typedef/Gu
90
90
### ` options: CreateTranscriptOptions `
91
91
92
92
The same options as [ generatefrommessages.md] ( generatefrommessages.md ' mention ') but adds the ` limit ` option which lets you limit set the number of messages to fetch.
93
+
94
+ ### ` options.limit: number `
95
+
96
+ The number of messages to fetch.
97
+
98
+ ### ` options.filter: (message: Message<boolean>) => boolean `
99
+
100
+ A function that will be called for each message to determine if it should be included in the transcript. If false, the message will not be included.
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ export async function createTranscript<T extends ExportReturnType = ExportReturn
97
97
// fetch messages
98
98
let allMessages : Message [ ] = [ ] ;
99
99
let lastMessageId : string | undefined ;
100
- const { limit } = options ;
100
+ const { limit, filter } = options ;
101
101
const resolvedLimit = typeof limit === 'undefined' || limit === - 1 ? Infinity : limit ;
102
102
103
103
// until there are no more messages, keep fetching
@@ -109,9 +109,11 @@ export async function createTranscript<T extends ExportReturnType = ExportReturn
109
109
110
110
// fetch messages
111
111
const messages = await channel . messages . fetch ( fetchLimitOptions ) ;
112
+ const filteredMessages = typeof filter === 'function' ? messages . filter ( filter ) : messages ;
112
113
113
114
// add the messages to the array
114
- allMessages . push ( ...messages . values ( ) ) ;
115
+ allMessages . push ( ...filteredMessages . values ( ) ) ;
116
+ // Get the last key of 'messages', not 'filteredMessages' because you will be refetching the same messages
115
117
lastMessageId = messages . lastKey ( ) ;
116
118
117
119
// if there are no more messages, break
Original file line number Diff line number Diff line change 1
- import type { AttachmentBuilder } from 'discord.js' ;
1
+ import type { AttachmentBuilder , Message } from 'discord.js' ;
2
2
import type { RenderMessageContext } from './generator' ;
3
3
4
4
export type AttachmentTypes = 'audio' | 'video' | 'image' | 'file' ;
@@ -72,5 +72,11 @@ export type CreateTranscriptOptions<T extends ExportReturnType> = Partial<
72
72
* The max amount of messages to fetch. Use `-1` to recursively fetch.
73
73
*/
74
74
limit : number ;
75
+
76
+ /**
77
+ * Filter messages of the channel
78
+ * @default (() => true)
79
+ */
80
+ filter : ( message : Message < boolean > ) => boolean ;
75
81
}
76
82
> ;
Original file line number Diff line number Diff line change @@ -4,8 +4,10 @@ import { createTranscript } from '../src';
4
4
import { config } from 'dotenv' ;
5
5
config ( ) ;
6
6
7
+ const { GuildMessages, Guilds, MessageContent } = discord . GatewayIntentBits ;
8
+
7
9
const client = new discord . Client ( {
8
- intents : [ discord . IntentsBitField . Flags . GuildMessages , discord . IntentsBitField . Flags . Guilds ] ,
10
+ intents : [ GuildMessages , Guilds , MessageContent ] ,
9
11
} ) ;
10
12
11
13
client . on ( 'ready' , async ( ) => {
@@ -18,7 +20,12 @@ client.on('ready', async () => {
18
20
}
19
21
20
22
console . time ( 'transcript' ) ;
21
- const attachment = await createTranscript ( channel ) ;
23
+
24
+ const attachment = await createTranscript ( channel , {
25
+ // Filter bot messages
26
+ filter : ( message ) => ! message . author . bot ,
27
+ } ) ;
28
+
22
29
console . timeEnd ( 'transcript' ) ;
23
30
24
31
await channel . send ( {
You can’t perform that action at this time.
0 commit comments