Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js");
  2. const client = new Discord.Client();
  3. const config = require("./config.json");
  4. const SQLite = require("better-sqlite3");
  5. const sql = new SQLite('./scores.sqlite');  
  6. const fs = require("fs");
  7.  
  8. // Error en warning berichten.
  9. client.on("error", (e) => console.error(e));
  10. client.on("warn", (e) => console.warn(e));
  11.  
  12. //Ready
  13. client.on("ready", () => {
  14.   console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
  15.   client.user.setActivity(`?help | Serving ${client.guilds.size} servers`);
  16.  
  17.  // Check if the table "points" exists.
  18.   const table = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'scores';").get();
  19.   if (!table['count(*)']) {
  20.     // If the table isn't there, create it and setup the database correctly.
  21.     sql.prepare("CREATE TABLE scores (id TEXT PRIMARY KEY, user TEXT, guild TEXT, points INTEGER, level INTEGER);").run();
  22.     // Ensure that the "id" row is always unique and indexed.
  23.     sql.prepare("CREATE UNIQUE INDEX idx_scores_id ON scores (id);").run();
  24.     sql.pragma("synchronous = 1");
  25.     sql.pragma("journal_mode = wal");
  26.   }
  27.  
  28.   // And then we have two prepared statements to get and set the score data.
  29.   client.getScore = sql.prepare("SELECT * FROM scores WHERE user = ? AND guild = ?");
  30.   client.setScore = sql.prepare("INSERT OR REPLACE INTO scores (id, user, guild, points, level) VALUES (@id, @user, @guild, @points, @level);");
  31.  
  32.  
  33. });
  34. //Guild Join
  35. client.on("guildCreate", guild => {
  36.   console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
  37.   client.user.setActivity(`Serving ${client.guilds.size} servers`);
  38. });
  39. //Guild Leave
  40. client.on("guildDelete", guild => {
  41.   console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
  42.   client.user.setActivity(`Serving ${client.guilds.size} servers`);
  43. });
  44. //Welcome
  45. client.on('guildMemberAdd', message => { // Commands Go Inside The client.on('message',
  46.   message.guild.channels.get('556881500088565761').send({embed: {
  47.    color:0x00AE86 ,
  48.    author: {
  49.     name: "Member Joined",
  50.     icon_url: message.user.avatarURL
  51.    },
  52.     thumbnail: message.user.avatarURL,
  53.    description: `Welcome ${message.user.tag}!! `,
  54.    timestamp: new Date(),
  55.    footer: {
  56.     text:  `ID ${message.user.id}`
  57.    }
  58.   }});
  59. });
  60. //Bye
  61. client.on('guildMemberRemove', message => { // Commands Go Inside The client.on('message',
  62.  message.guild.channels.get('556881500088565761').send({embed: {
  63.   color:16007746,
  64.   author: {
  65.    name : "Member Left",
  66.    icon_url: message.user.avatarURL
  67.   },
  68.   description: `Bye ${message.user.tag}`,
  69.   timestamp: new Date(),
  70.   footer: {
  71.    text: `ID ${message.user.id}`
  72.   }
  73.  }});
  74. });
  75.  
  76.  
  77. //Event
  78. client.on("message", async message => {
  79.   if(message.author.bot) return;
  80.    let score;
  81.   if (message.guild) {
  82.     score = client.getScore.get(message.author.id, message.guild.id);
  83.     if (!score) {
  84.       score = { id: `${message.guild.id}-${message.author.id}`, user: message.author.id, guild: message.guild.id, points: 0, level: 1 }
  85.     }
  86.     score.points++;
  87.     const curLevel = Math.floor(0.1 * Math.sqrt(score.points));
  88.     if(score.level < curLevel) {
  89.       score.level++;
  90.       message.reply(`You've leveled up to level **${curLevel}**! Ain't that dandy?`);
  91.     }
  92.     client.setScore.run(score);
  93.   }
  94.  
  95.  
  96.  //Tell prefix
  97.  if(message.content == "<@556954411084021761>") {
  98.    message.reply("My prefix is ``?``");
  99.  }
  100. //Anti invite  
  101.  if (message.content.includes("discord.gg")) {
  102.    console.log("deleted " + message.content + " from " + message.author)
  103.    message.delete(1);
  104.    message.channel.sendMessage("No links here, " + message.author)
  105.  }
  106.  
  107. // Mulai masuk commands
  108.  if(message.content.indexOf(config.prefix) !== 0) return;
  109.  
  110.   const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
  111.   const command = args.shift().toLowerCase();
  112.  
  113. //Points
  114.  if(command === "points") {
  115.   return message.reply(`You currently have :star: ${score.points} points and are level ${score.level}!`);
  116.  }  
  117. //Give points
  118.  if(command === "give") {
  119.   // Limited to guild owner - adjust to your own preference!
  120.   if(!message.author.id === message.guild.owner) return message.reply("You're not the boss of me, you can't do that!");
  121.    const user = message.mentions.users.first() || client.users.get(args[0]);
  122.   if(!user) return message.reply("You must mention someone or give their ID!");
  123.   const pointsToAdd = parseInt(args[1], 10);
  124.   if(!pointsToAdd) return message.reply("You didn't tell me how many points to give...")
  125.   // Get their current points.
  126.   let userscore = client.getScore.get(user.id, message.guild.id);
  127.   // It's possible to give points to a user we haven't seen, so we need to initiate defaults here too!
  128.   if (!userscore) {
  129.     userscore = { id: `${message.guild.id}-${user.id}`, user: user.id, guild: message.guild.id, points: 0, level: 1 }
  130.   }
  131.   userscore.points += pointsToAdd;
  132.   // We also want to update their level (but we won't notify them if it changes)
  133.   let userLevel = Math.floor(0.1 * Math.sqrt(score.points));
  134.   userscore.level = userLevel;
  135.   // And we save it!
  136.   client.setScore.run(userscore);
  137.   return message.channel.send(`${user.tag} has received ${pointsToAdd} points and now stands at ${userscore.points} points.`);
  138. }
  139. //Leaderboard
  140. if(command === "leaderboard") {
  141.  const top10 = sql.prepare("SELECT * FROM scores WHERE guild = ? ORDER BY points DESC LIMIT 10;").all(message.guild.id);
  142.  const embed = new Discord.RichEmbed()
  143.   .setTitle("Leaderboard")
  144.   .setAuthor(client.user.username, client.user.avatarURL)
  145.   .setDescription("Our top 10 points leaders!")
  146.   .setColor(0x00AE86);
  147.  
  148.  for(const data of top10) {
  149.   embed.addField(client.users.get(data.user).tag, `${data.points} points (level ${data.level})`);
  150.  }
  151.  return message.channel.send(embed);
  152. }
  153.  
  154. //Profile
  155.  if(command === "profile") {
  156.   let botembed = new Discord.RichEmbed()
  157.    .setTitle("**__ User Profile__**")
  158.    .setTimestamp(new Date())
  159.    .setColor(0x00AE86)
  160.    .setFooter("", `${client.user.avatarURL}`)
  161.    .setThumbnail(`${message.author.avatarURL}`)
  162.    .addField("Username :", `${message.author.username}`)
  163.    .addField("Level :",  `${score.level}`)
  164.    .addField("Points :", `:star: ${score.points}`)
  165.    .addField("Joined at :", `${message.member.joinedAt}`);
  166.   message.channel.send(botembed);
  167.  }
  168. //Ping  
  169.  if(command === "ping") {
  170.    const m = await message.channel.send("Ping?");
  171.    m.edit({embed: { color: 0x00AE86,description:  `Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`}});
  172.  }
  173. //Invite the bot
  174.  if(command === "invite") {
  175.    message.channel.send ({embed: { color:0x00AE86,title:"Invite me" ,description: "Invite the bot [click here](https://discordapp.com/api/oauth2/authorize?client_id=556954411084021761&permissions=0&scope=bot)" }});
  176.  }
  177. //Botinfo
  178.  if(command === "botinfo") {
  179.   let bicon = client.user.displayAvatarURL;
  180.   let botembed = new Discord.RichEmbed()
  181.    .setTitle("Bot Information")
  182.    .setColor(0x00AE86)
  183.    .setThumbnail(bicon)
  184.    .addField("Bot Name", client.user.username)
  185.    .addField("Servers", client.guilds.size)
  186.    .addField("Developer", "<@476542242333655051>")
  187.    .addField("Created On", "Sun, Mar 17 2019. Indonesia");
  188.   message.channel.send(botembed);
  189.  }
  190. //serverinfo
  191.  if(command === "serverinfo") {
  192.   let sicon = message.guild.iconURL;
  193.   let serverembed = new Discord.RichEmbed()
  194.    .setTitle("Server Information")
  195.    .setColor(0x00AE86)
  196.    .setThumbnail(sicon)
  197.    .addField("Server Name", message.guild.name)
  198.    .addField("Owner", message.guild.owner)
  199.    .addField("Region", message.guild.region)
  200.    .addField("Created On","Sun, 22 Apr 2018")
  201.    .addField("You Joined", message.member.joinedAt)
  202.    .addField("Channels", `${message.guild.channels.size}`)
  203.    .addField("Total Members", message.guild.memberCount);
  204.   message.channel.send(serverembed);
  205.  }
  206. //membercount
  207.  if(command === "membercount"){
  208.   let sericon = message.guild.iconURL;
  209.   let serverembed = new Discord.RichEmbed()
  210.    .setTitle("Member Count")
  211.    .setColor(0x00AE86)
  212.    .setThumbnail(sericon)
  213.    .addField("Members", message.guild.memberCount)
  214.   message.channel.send(serverembed);
  215.  }
  216. //Say  
  217.  if(command === "say") {
  218.   const sayMessage = args.join(" ");
  219.   message.delete().catch(O_o=>{});
  220.   message.channel.send ({embed: { color:0x00AE86,description: sayMessage }});    
  221.  }
  222. //Report
  223.  if(command === "report") {
  224.   let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  225.   let rreason = args.join(" ").slice(22);
  226.   var miss = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
  227.    .setColor(16032066)
  228.    .setAuthor(message.author.username, message.author.avatarURL)
  229.    .setTitle('Missing Arguments!')
  230.    .setDescription('Usage: ?report [@User] [Reason]')
  231.    .setTimestamp();
  232.   if(!rUser) return message.channel.send(miss); // Triggers if the user dosn't provide a reason for the warning
  233.  
  234.   let reportEmbed = new Discord.RichEmbed()
  235.    .setDescription("Reports")
  236.    .setColor("#f4cb42")
  237.    .addField("Reported User", `${rUser} with ID: ${rUser.id}`)
  238.    .addField("Reported By", `${message.author} with ID: ${message.author.id}`)
  239.    .addField("Channel", message.channel)
  240.    .addField("Time", message.createdAt)
  241.    .addField("Reason", rreason);
  242.  
  243.    let reportschannel = message.guild.channels.find(`name`, "reports");
  244.    if(!reportschannel) return message.channel.send("Couldn't find ``reports`` channel.");
  245.  
  246.    message.delete().catch(O_o=>{});
  247.    reportschannel.send(reportEmbed);
  248.  }
  249. //Warn
  250.  if(command === "warn") {
  251.   var embedColor = 16032066; // Change this to change the color of the embeds!
  252.   var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
  253.    .setColor(embedColor)
  254.    .setAuthor(message.author.username, message.author.avatarURL)
  255.    .setTitle('Insufficient Permissions!')
  256.    .setDescription('You need the `MANAGE_MESSAGES` permission to use this command!')
  257.    .setTimestamp();
  258.   var missingArgsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
  259.    .setColor(embedColor)
  260.    .setAuthor(message.author.username, message.author.avatarURL)
  261.    .setTitle('Missing Arguments!')
  262.    .setDescription('Usage: ?warn [@User] [Reason]')
  263.    .setTimestamp();
  264.   if(!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send(missingPermissionsEmbed); // Checks if the user has the permission
  265.    let mentioned = message.mentions.users.first(); // Gets the user mentioned!
  266.   if(!mentioned) return message.channel.send(missingArgsEmbed); // Triggers if the user donsn't tag a user in the message
  267.    let reason = args.slice(1).join(' ') // .slice(1) removes the user mention, .join(' ') joins all the words in the message, instead of just sending 1 word
  268.   if(!reason) return message.channel.send(missingArgsEmbed); // Triggers if the user dosn't provide a reason for the warning
  269.    var warningEmbed = new Discord.RichEmbed() // Creates the embed that's DM'ed to the user when their warned!
  270.     .setColor(embedColor)
  271.     .setAuthor(message.author.username, message.author.avatarURL)
  272.     .setTitle(`You've been warned in ${message.guild.name}`)
  273.    .addField('Warned by', message.author.tag)
  274.    .addField('Reason', reason)
  275.    .setTimestamp();
  276.   mentioned.send(warningEmbed); // DMs the user the above embed!
  277.   var warnSuccessfulEmbed = new Discord.RichEmbed() // Creates the embed thats returned to the person warning if its sent.
  278.    .setColor(embedColor)
  279.    .setTitle('User Successfully Warned!');
  280.   message.channel.send(warnSuccessfulEmbed); // Sends the warn successful embed
  281.   message.delete(); // Deletes the command
  282.   let warnlog = message.guild.channels.find(`name`, "logs");
  283.   if(!warnlog) return message.channel.send("Couldn't find reports channel.");
  284.    let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
  285.    let warn2 = new Discord.RichEmbed()
  286.     .setDescription("Warn")
  287.     .setColor(embedColor)
  288.     .addField("Warned User", `${rUser} with ID: ${rUser.id}`)
  289.     .addField("Warned By", `${message.author} with ID: ${message.author.id}`)
  290.     .addField("Channel", message.channel)
  291.     .addField("Time", message.createdAt)
  292.     .addField("Reason", reason);
  293.    message.delete().catch(O_o=>{});
  294.    warnlog.send(warn2);
  295. }
  296. //Kick  
  297. if(command === "kick") {
  298.  var embedColor = 16032066; // Change this to change the color of the embeds!
  299.  var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
  300.   .setColor(embedColor)
  301.   .setAuthor(message.author.username, message.author.avatarURL)
  302.   .setTitle('Insufficient Permissions!')
  303.   .setDescription('You need the `KICK_MEMBERS` permission to use this command!')
  304.   .setTimestamp();
  305.  var missingArgsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
  306.   .setColor(embedColor)
  307.   .setAuthor(message.author.username, message.author.avatarURL)
  308.   .setTitle('Missing Arguments!')
  309.   .setDescription('Usage: ?kick [@User] [Reason]')
  310.   .setTimestamp();
  311.  if(!message.member.hasPermission('KICK_MEMBERS'))
  312.   return message.channel.send(missingPermissionsEmbed); // Checks if the user has the permission
  313.  let mentioned = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); // Gets the user mentioned!
  314.  if(!mentioned)
  315.   return message.channel.send(missingArgsEmbed); // Triggers if the user donsn't tag a user in the message
  316.  //if(!mentioned.kickable)
  317.  if(mentioned.hasPermission("MANAGE_MESSAGES"))
  318.   return message.channel.send({embed: { title: "I can't do that", color:16007746 ,description: "I cannot kick this user! Do they have a higher role? Do I have kick permissions?" }});
  319.  let reason = args.join(" ").slice(22);
  320.   if(!reason) reason = "No reason provided";
  321.   let kickEmbed = new Discord.RichEmbed()
  322.    .setDescription("~Kick~")
  323.    .setColor("#e56b00")
  324.    .addField("Kicked User", `${mentioned.user.tag}`)
  325.    .addField("Kicked By", `<@${message.author.id}>`)
  326.    .addField("Kicked In", message.channel)
  327.    .addField("Tiime", message.createdAt)
  328.    .addField("Reason", `${reason}`);
  329.   let kickChannel = message.guild.channels.find(`name`, "logs");
  330.   if(!kickChannel) return message.channel.send("Can't find ``logs`` channel.");
  331.  
  332.   message.guild.member(mentioned).kick(reason);
  333.   kickChannel.send(kickEmbed);
  334.   message.channel.send(kickEmbed);
  335. }
  336. //Ban
  337. if(command === "ban") {
  338.  if(!message.member.hasPermission("BAN_MEMBERS"))
  339.   return message.reply({embed: { color:16007746 ,description:"Sorry, you don't have permissions to use this!" }});
  340.  let member = message.mentions.members.first();
  341.  if(!member)
  342.   return message.reply ({embed: { color:16007746 ,description: "Please mention a valid member of this server" }});
  343.  if(!member.bannable)
  344.   return message.reply({embed: { color:16007746 ,description: "I cannot Ban this user! Do they have a higher role? Do I have kick permissions?" }});
  345.  let reason = args.slice(1).join(' ');
  346.  if(!reason) reason = "No reason provided";
  347.   await member.ban(reason)
  348.   .catch(error => message.reply ({embed: { color:16007746 ,description: `Sorry ${message.author} I couldn't Ban because of : ${error}`}}));
  349.    let banEmbed = new Discord.RichEmbed()
  350.     .setDescription("~Ban~")
  351.     .setColor("#bc0000")
  352.     .addField("Banned User", `${member.user.tag}`)
  353.     .addField("Banned By", `<@${message.author.id}>`)
  354.     .addField("Banned In", message.channel)
  355.     .addField("Time", message.createdAt)
  356.     .addField("Reason", `${reason}`);
  357.     message.reply(banEmbed);
  358.   let banlog = message.guild.channels.find(`name`, "logs");
  359.   if(!banlog) return message.channel.send("Couldn't find Logs channel .");
  360.  
  361.   message.delete().catch(O_o=>{});
  362.   banlog.send(banEmbed);
  363.  }
  364.  
  365. //Clear
  366.  if(command === "clear") {
  367.   var embedColor = 16032066; // Change this to change the color of the embeds!
  368.   var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
  369.    .setColor(embedColor)
  370.    .setAuthor(message.author.username, message.author.avatarURL)
  371.    .setTitle('Insufficient Permissions!')
  372.    .setDescription('You need the `MANAGE_MESSAGES` permission to use this command!')
  373.    .setTimestamp();
  374.   var missingArgsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
  375.    .setColor(embedColor)
  376.    .setAuthor(message.author.username, message.author.avatarURL)
  377.    .setTitle('Missing Arguments!')
  378.    .setDescription('Usage: ``?clear [number]`` provide number between 2 and 100')
  379.    .setTimestamp();
  380.   if(!message.member.hasPermission("MANAGE_MESSAGES"))
  381.    return message.channel. send (missingPermissionsEmbed);
  382.   if(!args[0])
  383.     return message.channel.send (missingArgsEmbed);
  384.     message.channel.bulkDelete(args[0]).then(() => {
  385.     message.channel.send({embed: { color: 0x00AE86,description: `Cleared ${args[0]} messages.`}}).then(msg => msg.delete(5000));
  386.  
  387.   });
  388.  }
  389. //Addrole
  390.  if(command === "addrole") {
  391.   var embedColor = 16032066; // Change this to change the color of the embeds!
  392.   var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
  393.    .setColor(embedColor)
  394.    .setAuthor(message.author.username, message.author.avatarURL)
  395.    .setTitle('Insufficient Permissions!')
  396.    .setDescription('You need the `MANAGE_ROLES` permission to use this command!')
  397.    .setTimestamp();
  398.     if (!message.member.hasPermission("MANAGE_ROLES"))
  399.       return message.reply(missingPermissionsEmbed);
  400.     if (args[0] == "help") {
  401.       message.reply("Usage: ``!addrole <user> <role>``");
  402.     return;
  403.   }
  404.   let rMember = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
  405.   if (!rMember) return message.channel.send ({embed: { color: 16007746,description: "Please Mention Someone to give the role" }});
  406.   let role = args.join(" ").slice(22);
  407.   if (!role) return message.reply ({embed: { color:16007746 ,description: "Specify a role!" }});
  408.   let gRole = message.guild.roles.find(`name`, role);
  409.   if (!gRole) return message.reply ({embed: { color:16007746 ,description: "Couldn't find that role." }});
  410.  
  411.   if(rMember.roles.has(gRole.id)) return message.reply("They already have that role.");
  412.   await(rMember.addRole(gRole.id));
  413.  
  414.   try {
  415.     await rMember.send ({embed: { color:4387956 ,description: `Congrats, you have been given the role ${gRole.name}`}});
  416.   } catch (e) {
  417.     console.log(e.stack);
  418.     message.channel.send(`Congrats to <@${rMember.id}>, they have been given the role ${gRole.name}. We tried to DM them, but their DMs are locked.`)
  419.   }
  420.   }
  421. //delrole
  422.   if(command === "delrole") {
  423.    
  424.   if (!message.member.hasPermission("MANAGE_ROLES"))
  425.     return message.reply({embed: { color:16007746 ,description:"Sorry, you don't have permissions to use this!" }});
  426.  
  427.     if(args[0] == "help"){
  428.     message.reply("Usage: !removerole <user> <role>");
  429.     return;
  430.   }
  431.   let rMember = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
  432.   if (!rMember) return message.channel.send ({embed: { color: 16007746,description: "Please Mention Someone to give the role" }});
  433.   let role = args.join(" ").slice(22);
  434.   if (!role) return message.reply ({embed: { color:16007746 ,description: "Specify a role!" }});
  435.   let gRole = message.guild.roles.find(`name`, role);
  436.   if (!gRole) return message.reply ({embed: { color:16007746 ,description: "Couldn't find that role." }});
  437.  
  438.   if(!rMember.roles.has(gRole.id)) return message.reply("They don't have that role.");
  439.   await(rMember.removeRole(gRole.id));
  440.  
  441.   try{
  442.     await rMember.send(`RIP, you lost the ${gRole.name} role.`)
  443.   }catch(e){
  444.     message.channel.send(`RIP to <@${rMember.id}>, We removed ${gRole.name} from them. We tried to DM them, but their DMs are locked.`)
  445.   }
  446.  
  447.   }
  448. //Help
  449.   if(command === "help")  {
  450.     let boticon = client.user.displayAvatarURL;
  451.     let helpembed = new Discord.RichEmbed()
  452.        .setTitle("Help")
  453.        .setColor(0x00AE86)
  454.        .setThumbnail(boticon)
  455.        .addField("1. Core", "``ping``, ``help``, ``invite``, ``serverinfo``, ``botinfo``, ``report``")
  456.        .addField("2. Fun", "``say``")
  457.        .addField ("3. Level" , "``profile``, ``points``, ``give``, ``leaderboard``")
  458.        .addField("4. Moderation", "``kick``, ``ban``, ``warn``, ``clear``, ``addrole``, ``delrole``")
  459.        //.addField("NSFW", "``hentai``, ``cosplay``,``asian``");
  460.     message.channel.send(helpembed);
  461.   }
  462.    
  463.  
  464.  
  465. });
  466.  
  467.  
  468. client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement