MCPcopy Create free account
hub / github.com/RTByte/rtbyte / create

Method create

src/commands/Management/customcmds.js:68–93  ·  view source on GitHub ↗
(msg, [name, content])

Source from the content-addressed store, hash-verified

66 }
67
68 async create(msg, [name, content]) {
69 // Fetch the custom commands array from the guild's settings.
70 const customCommands = msg.guild.settings.get('commands.customCommands');
71
72 // If a command name or command response haven't been provided, stop process and inform user.
73 if (!name) return msg.reject(msg.language.get('COMMAND_CUSTOMCMDS_CREATE_NONAME'));
74 if (!content) return msg.reject(msg.language.get('COMMAND_CUSTOMCMDS_CREATE_NOCONTENT'));
75
76 // Update the provided custom command name to be all lowercase.
77 name = name.toLowerCase();
78
79 // If the provided custom command name exists as a native command, stop process and inform user.
80 if (this.client.commands.has(name)) return msg.reject(msg.language.get('COMMAND_CUSTOMCMDS_CREATE_NATIVE', name));
81
82 // If the provided custom command name is already used in another custom command, stop process and inform user.
83 const cmd = customCommands.find(command => command.name.toLowerCase() === name);
84 if (cmd) return msg.reject(msg.language.get('COMMAND_CUSTOMCMDS_CREATE_ALREADYEXISTS', name));
85
86 // Update the guild's custom commands array and add the new command.
87 await msg.guild.settings.update('commands.customCommands', { name: name, content: content });
88
89 // Emit custom command created event, which shows up in a guild's log channel if the option is enabled.
90 this.client.emit('customCmdCreate', msg, name, content);
91
92 return msg.affirm();
93 }
94
95 async delete(msg, [name]) {
96 // Fetch the custom commands array from the guild's settings.

Callers 8

enableMethod · 0.80
runMethod · 0.80
runMethod · 0.80
createRoleMethod · 0.80
runMethod · 0.80
createRoleMethod · 0.80
runMethod · 0.80
rtbyteInitMethod · 0.80

Calls 3

rejectMethod · 0.80
updateMethod · 0.80
affirmMethod · 0.80

Tested by

no test coverage detected