Haha-Yes/commands/admin/starboard.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

const { Command } = require('discord-akairo');
const fs = require('fs');
class StarBoardCommand extends Command {
2019-01-02 08:09:45 +01:00
constructor() {
super('starboard', {
aliases: ['starboard'],
category: 'admin',
channelRestriction: 'guild',
2019-01-12 17:00:36 +01:00
userPermissions: ['MANAGE_CHANNELS'],
2019-01-02 08:09:45 +01:00
description: {
content: 'Set starboard',
usage: '[]',
examples: ['']
}
});
}
2019-01-02 08:09:45 +01:00
async exec(message) {
let starboardChannel = message.channel.id;
2019-01-11 12:47:04 +01:00
fs.readFile(`./board/star${message.guild.id}.json`, 'utf8', function readFileCallback(err, data) {
2019-01-02 08:09:45 +01:00
if (err) {
2019-01-11 12:47:04 +01:00
console.log('yes');
fs.writeFile(`./board/star${message.guild.id}.json`, `{"starboard": "${starboardChannel}"}`, function (err) {
2019-01-02 08:09:45 +01:00
if (err) {
console.log(err);
}
});
} else {
let starboard = JSON.parse(data); //now it an object
starboard['starboard'] = starboardChannel;
var json = JSON.stringify(starboard); //convert it back to json
2019-01-11 12:47:04 +01:00
fs.writeFile(`./board/star${message.guild.id}.json`, json, 'utf8', function (err) {
2019-01-02 08:09:45 +01:00
if (err) {
2019-01-02 10:48:26 +01:00
2019-01-02 08:09:45 +01:00
return console.log(err);
}
});
}
});
2019-01-02 10:48:26 +01:00
2019-01-02 08:09:45 +01:00
return message.channel.send('This channel have been set as the starboard');
}
}
module.exports = StarBoardCommand;