Skip to content

feat: allow modules to export intents #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/getIntentsFromModules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { BotModule } from '../types/bot';

export const getIntentsFromModules = (modules: Record<string, BotModule>) => {
const intents = Object.values(modules).flatMap((module) => module.intents ?? []);
return [...new Set(intents)] as const;
};
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Client } from 'discord.js';

import { config } from './config';
import { getIntentsFromModules } from './core/getIntentsFromModules';
import { loadModules } from './core/loadModules';
import { modules } from './modules/modules';

const { discord } = config;

const client = new Client({
intents: ['Guilds', 'GuildVoiceStates', 'GuildMembers', 'GuildMessages', 'MessageContent'],
intents: getIntentsFromModules(modules),
});

await client.login(discord.token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ export const coolLinksManagement: BotModule = {
}
},
},
intents: ['GuildMessages', 'MessageContent', 'GuildMessageReactions'],
};
1 change: 1 addition & 0 deletions src/modules/patternReplace/patternReplace.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export const patternReplace: BotModule = {
await message.delete();
},
},
intents: ['GuildMessages', 'MessageContent'],
};
1 change: 1 addition & 0 deletions src/modules/quoiFeur/quoiFeur.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ export const quoiFeur: BotModule = {
ready: deleteRoleMutedOnCoubeh,
messageCreate: reactOnEndWithQuoi,
},
intents: ['Guilds', 'GuildMessages', 'MessageContent', 'GuildMessageReactions'],
};
1 change: 1 addition & 0 deletions src/modules/voiceOnDemand/voiceOnDemand.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ export const voiceOnDemand: BotModule = {
}
},
},
intents: ['GuildVoiceStates', 'GuildMembers'],
};
2 changes: 2 additions & 0 deletions src/types/bot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type {
ChatInputCommandInteraction,
ClientEvents,
ClientOptions,
RESTPostAPIChatInputApplicationCommandsJSONBody,
} from 'discord.js';

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