fetchPrefix not functioning as it should

So i have a default prefix what i am doing is if the author id is x then return a array of prefixes they can use if not just return the default prefix but it's not working as i am only able to use commands with "" meaning no prefix
No description
3 Replies
Xeno™
Xeno™11mo ago
PS: mention prefix works too
Favna
Favna11mo ago
Couple of things: 1. You cannot use this when inside the closure of an object without using a function expression. If you really want to use this then you have to use a function expression instead of an arrow function:
const client = new SapphireClient({
defaultPrefix: '?',
disableMentionPrefix: false,
enableLoaderTraceLoggings: true,
loadMessageCommandListeners: true,
fetchPrefix: function fetchPrefix(this: SapphireClient, message: Message) {
if (message.author.id === '1071843392268546068') return ['?', ''];
return this.options.defaultPrefix ?? '?';
},
});
const client = new SapphireClient({
defaultPrefix: '?',
disableMentionPrefix: false,
enableLoaderTraceLoggings: true,
loadMessageCommandListeners: true,
fetchPrefix: function fetchPrefix(this: SapphireClient, message: Message) {
if (message.author.id === '1071843392268546068') return ['?', ''];
return this.options.defaultPrefix ?? '?';
},
});
2. You should write the fallback return as shown above. this.options.defaultPrefix is valid and you should ideally try to return it. You then fallback to "?" manually if for whatever reason something goes wrong. The reason you cannot just write
`${this.options.defaultPrefix}`
`${this.options.defaultPrefix}`
is because defaultPrefix can be a readonly string[] and stringifying that will return item1,item2,item3 https://favna.s-ul.eu/UUKvqf5v.png 3. Flip '?' and '', again as shown above. Then it'll work. The reason is that the first matched prefix will be used and '' will match everything so when you then write ?command it'll match and think the command name is ?command instead of command
Xeno™
Xeno™11mo ago
oh ok
Want results from more Discord servers?
Add your server