Add editing feature to custom command
Also edit the default if argument isn't recognised.
This commit is contained in:
parent
274215f665
commit
c1bc55d456
2 changed files with 28 additions and 3 deletions
20
util/editCustomCommand.js
Normal file
20
util/editCustomCommand.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const fs = require('fs')
|
||||
module.exports = function(customName, author, newCustomMessage){
|
||||
const customPath = './data/customCommands.json';
|
||||
let sendText = "This custom command does not exist.";
|
||||
let json = fs.readFileSync(customPath, 'utf8');
|
||||
let customCommands = JSON.parse(json)
|
||||
customCommands.forEach(function (customCommand) {
|
||||
if (customCommand.customName === customName) {
|
||||
if(customCommand.author === author){
|
||||
customCommand.customMessage = newCustomMessage;
|
||||
fs.writeFileSync(customPath, JSON.stringify(customCommands, null, 4))
|
||||
sendText = `${customName} has been updated.`;
|
||||
}else {
|
||||
sendText = "You do not own this custom command.\nOnly the one who created the custom command can edit it."
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return sendText;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue