Haha-Yes/commands/admin/shameboard.js

43 lines
1.7 KiB
JavaScript
Raw Normal View History

const { Command } = require('discord-akairo');
const fs = require('fs');
2019-01-01 05:19:09 +01:00
class shamoeboardCommand extends Command {
constructor() {
2019-01-01 05:19:09 +01:00
super('shamoeboard', {
aliases: ['shamoeboard'],
category: 'admin',
channelRestriction: 'guild',
userPermissions: ['ADMINISTRATOR'],
description: {
2019-01-01 05:19:09 +01:00
content: 'Set shamoeboard',
usage: '[]',
examples: ['']
}
});
}
2019-01-01 05:19:09 +01:00
async exec(message) {
let shamoeboardChannel = message.channel.id;
2019-01-01 05:19:09 +01:00
fs.readFile(`./shamoeboard/${message.guild.id}.json`, 'utf8', function readFileCallback(err, data){
if (err){
2019-01-01 05:19:09 +01:00
fs.writeFile(`./shamoeboard/${message.guild.id}.json`, `{"shamoeboard": "${shamoeboardChannel}"}`, function (err) {
if (err){
console.log(err);
}
2019-01-01 05:19:09 +01:00
return message.channel.send(`This channel have been set as the shamoeboard`);
})
} else {
2019-01-01 05:19:09 +01:00
let shamoeboard = JSON.parse(data); //now it an object
shamoeboard ['shamoeboard'] = shamoeboardChannel;
var json = JSON.stringify(shamoeboard); //convert it back to json
fs.writeFile(`./shamoeboard/${message.guild.id}.json`, json, 'utf8', function(err) {
if(err) {
return console.log(err);
}
})}});
2019-01-01 05:19:09 +01:00
return message.channel.send(`This channel have been set as the shamoeboard`);
}
}
2019-01-01 05:19:09 +01:00
module.exports = shamoeboardCommand;