Skip to content

Commit 7dbc528

Browse files
committed
feat: add server specific prefixes (based on PRs by @jbasalone)
1 parent 7cbf5d1 commit 7dbc528

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/config.ts

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import {
99

1010
const defaultConfig: Config = {
1111
prefix: '!',
12+
customPrefixes: [
13+
{
14+
guildId: "GUILD_ID",
15+
prefix: "?"
16+
}
17+
],
18+
1219
ownerId: 'YOUR_USER_ID',
1320
eventsFolder: 'events',
1421
commandsFolder: 'commands',

src/handler/events/listeners/messageCreate.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@ import { CommandHandler } from '../../commands/services/CommandHandler';
77
export default new Event({
88
name: Events.MessageCreate,
99
async execute(message: Message): Promise<void> {
10-
if (!client.user || message.author.bot || !message.content.startsWith(config.prefix)) return;
10+
if (!client.user || message.author.bot) {
11+
return;
12+
}
13+
14+
let prefix: string = config.prefix;
15+
if (message.guild?.id && config.customPrefixes) {
16+
const customPrefix: string | undefined = config.customPrefixes.find(
17+
(p) => p.guildId === message.guild!.id,
18+
)?.prefix;
19+
if (customPrefix) prefix = customPrefix;
20+
}
21+
22+
if (!message.content.startsWith(prefix)) {
23+
return;
24+
}
25+
1126
await CommandHandler.handlePrefixCommand(message);
1227
},
1328
});

src/handler/types/Config.ts

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88

99
export interface Config {
1010
prefix: string;
11+
customPrefixes?: CustomPrefix[];
1112
ownerId?: string;
1213
eventsFolder: string;
1314
commandsFolder: string;
@@ -25,3 +26,8 @@ export interface LogChannelConfig {
2526
commandType: string,
2627
) => Promise<MessageReplyOptions>;
2728
}
29+
30+
export interface CustomPrefix {
31+
guildId: string;
32+
prefix: string;
33+
}

0 commit comments

Comments
 (0)