-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeywordDispatch.js
More file actions
24 lines (23 loc) · 816 Bytes
/
keywordDispatch.js
File metadata and controls
24 lines (23 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* This class searches for any keyword handlers with the message content as their name, or an alias and executes the
* handler if found.
*/
module.exports = {
handle(client, message) {
const messageContent = message.content.trim();
const keyword = client.keywords.get(messageContent)
|| client.keywords.find(kwd => kwd.aliases && kwd.aliases.includes(messageContent));
if(keyword) {
try {
// Run the command
keyword.execute(message).catch((err) => {
console.error(`Failed running keyword handler ${keyword.name}: "${err.message}"`)
});
return true;
} catch(error) {
console.error(error);
}
return false;
}
}
}