Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require("fs");
- const Discord = require("discord.js");
- const discord = new Discord.Client();
- const secret = JSON.parse(fs.readFileSync("secret.json"));
- // TODO: Embed menu api
- const PREFIX = "kp!";
- const COLOR = 0x2c9ff7;
- const MENU_LIFETIME = 4;
- let menus = [];
- class Menu {
- constructor() {
- }
- }
- class PageMenu {
- constructor(user) {
- this.user = user;
- }
- }
- const roles = {
- "432939088711254037": { // Moderator
- commands: ["help", "eval"]
- },
- "431418564755456000": { // @everyone
- commands: ["help"]
- }
- };
- const commands = {
- "help": {
- usage: "help (<command>)",
- description: "Shows a list of all commands and tells you more information about a specific command",
- use: function(args, message) {
- if (args.length === 0) {
- message.channel.send(new Discord.RichEmbed({
- title: "Kunskapsbotten Help",
- color: COLOR,
- fields: [
- {
- name: "Info",
- value: "Kunskapsbotten är en bot."
- },
- {
- name: "Användning",
- value: "Använd pilknapparna för att navigera menyer som denna.\n:1234: Knappen låter dig hoppa till ett specifierat sidnummer.\n:eject: Knappen stänger menyn"
- }
- ],
- footer: {
- text: "Sida 1 av mom gay"
- }
- })).then(async function(message) {
- await message.react("⏮");
- await message.react("⬅");
- await message.react("➡");
- await message.react("⏭");
- await message.react("🔢");
- await message.react("⏏");
- });
- } else if (args[0].toLowerCase() in commands) {
- let command = args[0].toLowerCase();
- message.channel.send(new Discord.RichEmbed({
- title: command,
- color: COLOR,
- description: commands[command].description,
- fields: [
- {
- name: "Använding: " + commands[command].usage,
- value: ""
- }
- ],
- footer: {
- text: "Kategori: Info"
- }
- }));
- }
- return true;
- }
- },
- "eval": {
- usage: "eval <javascript>",
- description: "Run a piece of code on the server.",
- use: function(args, message) {
- if (args.length === 0) {
- return false;
- } else {
- let result;
- try {
- result = eval(args.join(" "));
- } catch(e) {
- message.channel.send(e.toString());
- return true;
- }
- // Idk if this is equivalent to just JSON.stringify lol.
- if (typeof result == "undefined") {
- message.channel.send("`undefined`");
- } else if (typeof result == "number") {
- message.channel.send("`" + result + "`");
- } else if (typeof result == "string") {
- message.channel.send("`\"" + result + "\"`");
- } else if (Array.isArray(result)) {
- message.channel.send("`" + JSON.stringify(result) + "`");
- } else {
- message.channel.send("`" + result.toString() + "`");
- }
- return true;
- }
- }
- }
- };
- discord.on("ready", function() {
- console.log("Ready");
- });
- discord.on("message", function(message) {
- if (message.author.bot) {
- return;
- }
- if (message.content.startsWith(PREFIX)) {
- let content = message.content.slice(PREFIX.length).split(" ");
- let command = content[0].toLowerCase();
- if (command in commands) {
- let canUse = false;
- let rolesArray = message.member.roles.array();
- let permission = message.member.roles.some(function(role) {
- return (role.id in roles) && roles[role.id].commands.includes(command);
- });
- if (permission) {
- let result = commands[command].use(content.slice(1), message);
- if (!result) {
- message.channel.send("**:x: " + command + " usage:** `" + commands[command].usage + "`");
- }
- } else {
- message.channel.send(":x: You don't have permission to use this command!");
- }
- }
- // Don't send an error message if the command doesn't exist.
- }
- });
- discord.on("messageReactionAdd", function(reaction, user) {
- });
- discord.login(secret.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement