check if message starts with the prefix

how can I check if a message starts with the bot's prefix? Including the bot's mention
Solution:
Seeing as this is a follow up from your previous post and you do not have access to the command context you'll have to parse it out manually ```js const possiblePrefixes = ['!', '<@PUT_YOUR_CLIENT_ID_HERE_FOR_THE_MENTION>', 'etc']; const msg = {...
No description
Jump to solution
3 Replies
Solution
Favna
Favna•11mo ago
Seeing as this is a follow up from your previous post and you do not have access to the command context you'll have to parse it out manually
const possiblePrefixes = ['!', '<@PUT_YOUR_CLIENT_ID_HERE_FOR_THE_MENTION>', 'etc'];
const msg = {
content: '!mycommand myoptions'
};

let startsWithPrefix = false;

for (let prefix of possiblePrefixes) {
if (msg.content.startsWith(prefix)) {
startsWithPrefix = true;
break;
}
}

console.log(startsWithPrefix); // prints true if msg.content starts with one of the possiblePrefixes
const possiblePrefixes = ['!', '<@PUT_YOUR_CLIENT_ID_HERE_FOR_THE_MENTION>', 'etc'];
const msg = {
content: '!mycommand myoptions'
};

let startsWithPrefix = false;

for (let prefix of possiblePrefixes) {
if (msg.content.startsWith(prefix)) {
startsWithPrefix = true;
break;
}
}

console.log(startsWithPrefix); // prints true if msg.content starts with one of the possiblePrefixes
No description
Favna
Favna•11mo ago
As an aside, did you delete your other thread? I was looking for it but I can't find it anymore. No big deal if so, just surprised.
-Carlos👑
-Carlos👑OP•11mo ago
I don't think I have permission to delete threads i just closed it
Want results from more Discord servers?
Add your server