Skip to content

Commit f2c338d

Browse files
neolectronpotb
authored andcommitted
feat: allow modules to export intents (#55)
1 parent cce59b2 commit f2c338d

File tree

7 files changed

+15
-1
lines changed

7 files changed

+15
-1
lines changed

src/core/getIntentsFromModules.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { BotModule } from '../types/bot';
2+
3+
export const getIntentsFromModules = (modules: Record<string, BotModule>) => {
4+
const intents = Object.values(modules).flatMap((module) => module.intents ?? []);
5+
return [...new Set(intents)] as const;
6+
};

src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Client } from 'discord.js';
22

33
import { config } from './config';
4+
import { getIntentsFromModules } from './core/getIntentsFromModules';
45
import { loadModules } from './core/loadModules';
56
import { modules } from './modules/modules';
67

78
const { discord } = config;
9+
810
const client = new Client({
9-
intents: ['Guilds', 'GuildVoiceStates', 'GuildMembers', 'GuildMessages', 'MessageContent'],
11+
intents: getIntentsFromModules(modules),
1012
});
1113

1214
await client.login(discord.token);

src/modules/coolLinksManagement/coolLinksManagement.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,5 @@ export const coolLinksManagement: BotModule = {
7777
}
7878
},
7979
},
80+
intents: ['GuildMessages', 'MessageContent', 'GuildMessageReactions'],
8081
};

src/modules/patternReplace/patternReplace.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ export const patternReplace: BotModule = {
3838
await message.delete();
3939
},
4040
},
41+
intents: ['GuildMessages', 'MessageContent'],
4142
};

src/modules/quoiFeur/quoiFeur.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ export const quoiFeur: BotModule = {
3232
ready: deleteRoleMutedOnCoubeh,
3333
messageCreate: reactOnEndWithQuoi,
3434
},
35+
intents: ['Guilds', 'GuildMessages', 'MessageContent', 'GuildMessageReactions'],
3536
};

src/modules/voiceOnDemand/voiceOnDemand.module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,4 +93,5 @@ export const voiceOnDemand: BotModule = {
9393
}
9494
},
9595
},
96+
intents: ['GuildVoiceStates', 'GuildMembers'],
9697
};

src/types/bot.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
ChatInputCommandInteraction,
33
ClientEvents,
4+
ClientOptions,
45
RESTPostAPIChatInputApplicationCommandsJSONBody,
56
} from 'discord.js';
67

@@ -22,4 +23,5 @@ export type BotModule = {
2223
eventHandlers?: {
2324
[key in keyof ClientEvents]?: EventHandler<key>;
2425
};
26+
intents?: ClientOptions['intents'];
2527
};

0 commit comments

Comments
 (0)