Skip to content

Commit

Permalink
Create viewcode.js
Browse files Browse the repository at this point in the history
Allows users to view the code of ANY command
  • Loading branch information
Crenshaw committed Apr 6, 2021
1 parent 6a0215a commit f35e66e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions commands/Information/viewcode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const fs = require('fs');
const got = require("got");
const { MessageEmbed } = require("discord.js");

module.exports = {
name: "viewcode",
description: "View the code of a command",
usage: "viewcode <command name/alias>",
groups: ["information"],
DM: true,
cooldown: {type: "map", time: 10},
aliases: ["vc"],
run: async (client, message, args) => {
let command = client.commands.get(args[0]) || client.commands.get(client.aliases.get(args[0]));
if (!command) return client.err(message, "ViewCode", "Command not found");

const commandFolders = fs.readdirSync('./commands');
const folderName = commandFolders.find(folder => fs.readdirSync(`./commands/${folder}`).indexOf(`${command.name}.js`) > -1);
const url = `https://raw.githubusercontent.com/Crenshaw1312/Jackson/main/commands/${folderName}/${command.name}.js`

// Get the Code
let code = await got(url);
code = code.body;
if (code.length > 2040) {
code = "Command was too large, please just click the link above"
}

const embed = new MessageEmbed()
.setTitle("ViewCode")
.setColor(0x4B0082)
.setURL(url)
.setDescription(`\`\`\`js\n${code}\n\`\`\``);
return message.reply(embed);
}
}

0 comments on commit f35e66e

Please sign in to comment.