You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the above command as an example, if a user on Discord runs
66
-
`!ping arg1 arg2 arg3`, the value of `args` will equal
67
-
`['arg1', 'arg2', 'arg3']`.
60
+
`!ping john jack jane`, the value of `args` will equal
61
+
`['john', 'jack', 'jane']`.
62
+
63
+
## Custom Prefixes
64
+
65
+
The simplest way to set a custom prefix is using the
66
+
`setPrefixResolver` method on the `commandkit` instance:
67
+
68
+
```ts title="src/app.ts"
69
+
import { commandkit } from'commandkit';
70
+
71
+
commandkit.setPrefixResolver(async (message) => {
72
+
return'?';
73
+
});
74
+
```
75
+
76
+
This sets a global prefix of `?` for all message commands. Your bot
77
+
will now respond to commands like `?help` or `?ping`.
78
+
79
+
:::tip
80
+
81
+
You can return an array of strings to support multiple prefixes
82
+
simultaneously:
83
+
84
+
```ts
85
+
return ['?', '!', '>'];
86
+
```
87
+
88
+
:::
89
+
90
+
### Guild-Specific Prefixes
91
+
92
+
For a more dynamic approach, you might want different prefixes for
93
+
different guilds. Here's how to implement that:
94
+
95
+
```ts title="src/app.ts"
96
+
import { commandkit } from'commandkit';
97
+
import { database } from'../database'; // This is a mock database
98
+
99
+
commandkit.setPrefixResolver(async (message) => {
100
+
const guildSettings =awaitdatabase.findUnique({
101
+
where: { guildId },
102
+
});
103
+
104
+
returnguildSettings?.prefix??'!'; // Fallback to '!' if no prefix is found
105
+
});
106
+
```
107
+
108
+
:::warning
109
+
110
+
The `setPrefixResolver` method runs on every message, so it's important to make sure that it's as lightweight as possible. To help with performance, you may want to implement caching, which CommandKit also supports with the [`@commandkit/cache`](../05-official-plugins/03-commandkit-cache.mdx) official plugin.
0 commit comments