Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const client = new Discord.Client();
- const config = require("./config.json");
- const SQLite = require("better-sqlite3");
- const sql = new SQLite('./scores.sqlite');
- const fs = require("fs");
- // Error en warning berichten.
- client.on("error", (e) => console.error(e));
- client.on("warn", (e) => console.warn(e));
- //Ready
- client.on("ready", () => {
- console.log(`Bot has started, with ${client.users.size} users, in ${client.channels.size} channels of ${client.guilds.size} guilds.`);
- client.user.setActivity(`?help | Serving ${client.guilds.size} servers`);
- // Check if the table "points" exists.
- const table = sql.prepare("SELECT count(*) FROM sqlite_master WHERE type='table' AND name = 'scores';").get();
- if (!table['count(*)']) {
- // If the table isn't there, create it and setup the database correctly.
- sql.prepare("CREATE TABLE scores (id TEXT PRIMARY KEY, user TEXT, guild TEXT, points INTEGER, level INTEGER);").run();
- // Ensure that the "id" row is always unique and indexed.
- sql.prepare("CREATE UNIQUE INDEX idx_scores_id ON scores (id);").run();
- sql.pragma("synchronous = 1");
- sql.pragma("journal_mode = wal");
- }
- // And then we have two prepared statements to get and set the score data.
- client.getScore = sql.prepare("SELECT * FROM scores WHERE user = ? AND guild = ?");
- client.setScore = sql.prepare("INSERT OR REPLACE INTO scores (id, user, guild, points, level) VALUES (@id, @user, @guild, @points, @level);");
- });
- //Guild Join
- client.on("guildCreate", guild => {
- console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
- client.user.setActivity(`Serving ${client.guilds.size} servers`);
- });
- //Guild Leave
- client.on("guildDelete", guild => {
- console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
- client.user.setActivity(`Serving ${client.guilds.size} servers`);
- });
- //Welcome
- client.on('guildMemberAdd', message => { // Commands Go Inside The client.on('message',
- message.guild.channels.get('556881500088565761').send({embed: {
- color:0x00AE86 ,
- author: {
- name: "Member Joined",
- icon_url: message.user.avatarURL
- },
- thumbnail: message.user.avatarURL,
- description: `Welcome ${message.user.tag}!! `,
- timestamp: new Date(),
- footer: {
- text: `ID ${message.user.id}`
- }
- }});
- });
- //Bye
- client.on('guildMemberRemove', message => { // Commands Go Inside The client.on('message',
- message.guild.channels.get('556881500088565761').send({embed: {
- color:16007746,
- author: {
- name : "Member Left",
- icon_url: message.user.avatarURL
- },
- description: `Bye ${message.user.tag}`,
- timestamp: new Date(),
- footer: {
- text: `ID ${message.user.id}`
- }
- }});
- });
- //Event
- client.on("message", async message => {
- if(message.author.bot) return;
- let score;
- if (message.guild) {
- score = client.getScore.get(message.author.id, message.guild.id);
- if (!score) {
- score = { id: `${message.guild.id}-${message.author.id}`, user: message.author.id, guild: message.guild.id, points: 0, level: 1 }
- }
- score.points++;
- const curLevel = Math.floor(0.1 * Math.sqrt(score.points));
- if(score.level < curLevel) {
- score.level++;
- message.reply(`You've leveled up to level **${curLevel}**! Ain't that dandy?`);
- }
- client.setScore.run(score);
- }
- //Tell prefix
- if(message.content == "<@556954411084021761>") {
- message.reply("My prefix is ``?``");
- }
- //Anti invite
- if (message.content.includes("discord.gg")) {
- console.log("deleted " + message.content + " from " + message.author)
- message.delete(1);
- message.channel.sendMessage("No links here, " + message.author)
- }
- // Mulai masuk commands
- if(message.content.indexOf(config.prefix) !== 0) return;
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- //Points
- if(command === "points") {
- return message.reply(`You currently have :star: ${score.points} points and are level ${score.level}!`);
- }
- //Give points
- if(command === "give") {
- // Limited to guild owner - adjust to your own preference!
- if(!message.author.id === message.guild.owner) return message.reply("You're not the boss of me, you can't do that!");
- const user = message.mentions.users.first() || client.users.get(args[0]);
- if(!user) return message.reply("You must mention someone or give their ID!");
- const pointsToAdd = parseInt(args[1], 10);
- if(!pointsToAdd) return message.reply("You didn't tell me how many points to give...")
- // Get their current points.
- let userscore = client.getScore.get(user.id, message.guild.id);
- // It's possible to give points to a user we haven't seen, so we need to initiate defaults here too!
- if (!userscore) {
- userscore = { id: `${message.guild.id}-${user.id}`, user: user.id, guild: message.guild.id, points: 0, level: 1 }
- }
- userscore.points += pointsToAdd;
- // We also want to update their level (but we won't notify them if it changes)
- let userLevel = Math.floor(0.1 * Math.sqrt(score.points));
- userscore.level = userLevel;
- // And we save it!
- client.setScore.run(userscore);
- return message.channel.send(`${user.tag} has received ${pointsToAdd} points and now stands at ${userscore.points} points.`);
- }
- //Leaderboard
- if(command === "leaderboard") {
- const top10 = sql.prepare("SELECT * FROM scores WHERE guild = ? ORDER BY points DESC LIMIT 10;").all(message.guild.id);
- const embed = new Discord.RichEmbed()
- .setTitle("Leaderboard")
- .setAuthor(client.user.username, client.user.avatarURL)
- .setDescription("Our top 10 points leaders!")
- .setColor(0x00AE86);
- for(const data of top10) {
- embed.addField(client.users.get(data.user).tag, `${data.points} points (level ${data.level})`);
- }
- return message.channel.send(embed);
- }
- //Profile
- if(command === "profile") {
- let botembed = new Discord.RichEmbed()
- .setTitle("**__ User Profile__**")
- .setTimestamp(new Date())
- .setColor(0x00AE86)
- .setFooter("", `${client.user.avatarURL}`)
- .setThumbnail(`${message.author.avatarURL}`)
- .addField("Username :", `${message.author.username}`)
- .addField("Level :", `${score.level}`)
- .addField("Points :", `:star: ${score.points}`)
- .addField("Joined at :", `${message.member.joinedAt}`);
- message.channel.send(botembed);
- }
- //Ping
- if(command === "ping") {
- const m = await message.channel.send("Ping?");
- m.edit({embed: { color: 0x00AE86,description: `Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`}});
- }
- //Invite the bot
- if(command === "invite") {
- 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)" }});
- }
- //Botinfo
- if(command === "botinfo") {
- let bicon = client.user.displayAvatarURL;
- let botembed = new Discord.RichEmbed()
- .setTitle("Bot Information")
- .setColor(0x00AE86)
- .setThumbnail(bicon)
- .addField("Bot Name", client.user.username)
- .addField("Servers", client.guilds.size)
- .addField("Developer", "<@476542242333655051>")
- .addField("Created On", "Sun, Mar 17 2019. Indonesia");
- message.channel.send(botembed);
- }
- //serverinfo
- if(command === "serverinfo") {
- let sicon = message.guild.iconURL;
- let serverembed = new Discord.RichEmbed()
- .setTitle("Server Information")
- .setColor(0x00AE86)
- .setThumbnail(sicon)
- .addField("Server Name", message.guild.name)
- .addField("Owner", message.guild.owner)
- .addField("Region", message.guild.region)
- .addField("Created On","Sun, 22 Apr 2018")
- .addField("You Joined", message.member.joinedAt)
- .addField("Channels", `${message.guild.channels.size}`)
- .addField("Total Members", message.guild.memberCount);
- message.channel.send(serverembed);
- }
- //membercount
- if(command === "membercount"){
- let sericon = message.guild.iconURL;
- let serverembed = new Discord.RichEmbed()
- .setTitle("Member Count")
- .setColor(0x00AE86)
- .setThumbnail(sericon)
- .addField("Members", message.guild.memberCount)
- message.channel.send(serverembed);
- }
- //Say
- if(command === "say") {
- const sayMessage = args.join(" ");
- message.delete().catch(O_o=>{});
- message.channel.send ({embed: { color:0x00AE86,description: sayMessage }});
- }
- //Report
- if(command === "report") {
- let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
- let rreason = args.join(" ").slice(22);
- var miss = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
- .setColor(16032066)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Missing Arguments!')
- .setDescription('Usage: ?report [@User] [Reason]')
- .setTimestamp();
- if(!rUser) return message.channel.send(miss); // Triggers if the user dosn't provide a reason for the warning
- let reportEmbed = new Discord.RichEmbed()
- .setDescription("Reports")
- .setColor("#f4cb42")
- .addField("Reported User", `${rUser} with ID: ${rUser.id}`)
- .addField("Reported By", `${message.author} with ID: ${message.author.id}`)
- .addField("Channel", message.channel)
- .addField("Time", message.createdAt)
- .addField("Reason", rreason);
- let reportschannel = message.guild.channels.find(`name`, "reports");
- if(!reportschannel) return message.channel.send("Couldn't find ``reports`` channel.");
- message.delete().catch(O_o=>{});
- reportschannel.send(reportEmbed);
- }
- //Warn
- if(command === "warn") {
- var embedColor = 16032066; // Change this to change the color of the embeds!
- var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Insufficient Permissions!')
- .setDescription('You need the `MANAGE_MESSAGES` permission to use this command!')
- .setTimestamp();
- var missingArgsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Missing Arguments!')
- .setDescription('Usage: ?warn [@User] [Reason]')
- .setTimestamp();
- if(!message.member.hasPermission('MANAGE_MESSAGES')) return message.channel.send(missingPermissionsEmbed); // Checks if the user has the permission
- let mentioned = message.mentions.users.first(); // Gets the user mentioned!
- if(!mentioned) return message.channel.send(missingArgsEmbed); // Triggers if the user donsn't tag a user in the message
- 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
- if(!reason) return message.channel.send(missingArgsEmbed); // Triggers if the user dosn't provide a reason for the warning
- var warningEmbed = new Discord.RichEmbed() // Creates the embed that's DM'ed to the user when their warned!
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle(`You've been warned in ${message.guild.name}`)
- .addField('Warned by', message.author.tag)
- .addField('Reason', reason)
- .setTimestamp();
- mentioned.send(warningEmbed); // DMs the user the above embed!
- var warnSuccessfulEmbed = new Discord.RichEmbed() // Creates the embed thats returned to the person warning if its sent.
- .setColor(embedColor)
- .setTitle('User Successfully Warned!');
- message.channel.send(warnSuccessfulEmbed); // Sends the warn successful embed
- message.delete(); // Deletes the command
- let warnlog = message.guild.channels.find(`name`, "logs");
- if(!warnlog) return message.channel.send("Couldn't find reports channel.");
- let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
- let warn2 = new Discord.RichEmbed()
- .setDescription("Warn")
- .setColor(embedColor)
- .addField("Warned User", `${rUser} with ID: ${rUser.id}`)
- .addField("Warned By", `${message.author} with ID: ${message.author.id}`)
- .addField("Channel", message.channel)
- .addField("Time", message.createdAt)
- .addField("Reason", reason);
- message.delete().catch(O_o=>{});
- warnlog.send(warn2);
- }
- //Kick
- if(command === "kick") {
- var embedColor = 16032066; // Change this to change the color of the embeds!
- var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Insufficient Permissions!')
- .setDescription('You need the `KICK_MEMBERS` permission to use this command!')
- .setTimestamp();
- var missingArgsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Missing Arguments!')
- .setDescription('Usage: ?kick [@User] [Reason]')
- .setTimestamp();
- if(!message.member.hasPermission('KICK_MEMBERS'))
- return message.channel.send(missingPermissionsEmbed); // Checks if the user has the permission
- let mentioned = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0])); // Gets the user mentioned!
- if(!mentioned)
- return message.channel.send(missingArgsEmbed); // Triggers if the user donsn't tag a user in the message
- //if(!mentioned.kickable)
- if(mentioned.hasPermission("MANAGE_MESSAGES"))
- 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?" }});
- let reason = args.join(" ").slice(22);
- if(!reason) reason = "No reason provided";
- let kickEmbed = new Discord.RichEmbed()
- .setDescription("~Kick~")
- .setColor("#e56b00")
- .addField("Kicked User", `${mentioned.user.tag}`)
- .addField("Kicked By", `<@${message.author.id}>`)
- .addField("Kicked In", message.channel)
- .addField("Tiime", message.createdAt)
- .addField("Reason", `${reason}`);
- let kickChannel = message.guild.channels.find(`name`, "logs");
- if(!kickChannel) return message.channel.send("Can't find ``logs`` channel.");
- message.guild.member(mentioned).kick(reason);
- kickChannel.send(kickEmbed);
- message.channel.send(kickEmbed);
- }
- //Ban
- if(command === "ban") {
- if(!message.member.hasPermission("BAN_MEMBERS"))
- return message.reply({embed: { color:16007746 ,description:"Sorry, you don't have permissions to use this!" }});
- let member = message.mentions.members.first();
- if(!member)
- return message.reply ({embed: { color:16007746 ,description: "Please mention a valid member of this server" }});
- if(!member.bannable)
- return message.reply({embed: { color:16007746 ,description: "I cannot Ban this user! Do they have a higher role? Do I have kick permissions?" }});
- let reason = args.slice(1).join(' ');
- if(!reason) reason = "No reason provided";
- await member.ban(reason)
- .catch(error => message.reply ({embed: { color:16007746 ,description: `Sorry ${message.author} I couldn't Ban because of : ${error}`}}));
- let banEmbed = new Discord.RichEmbed()
- .setDescription("~Ban~")
- .setColor("#bc0000")
- .addField("Banned User", `${member.user.tag}`)
- .addField("Banned By", `<@${message.author.id}>`)
- .addField("Banned In", message.channel)
- .addField("Time", message.createdAt)
- .addField("Reason", `${reason}`);
- message.reply(banEmbed);
- let banlog = message.guild.channels.find(`name`, "logs");
- if(!banlog) return message.channel.send("Couldn't find Logs channel .");
- message.delete().catch(O_o=>{});
- banlog.send(banEmbed);
- }
- //Clear
- if(command === "clear") {
- var embedColor = 16032066; // Change this to change the color of the embeds!
- var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Insufficient Permissions!')
- .setDescription('You need the `MANAGE_MESSAGES` permission to use this command!')
- .setTimestamp();
- var missingArgsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the command isnt run right
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Missing Arguments!')
- .setDescription('Usage: ``?clear [number]`` provide number between 2 and 100')
- .setTimestamp();
- if(!message.member.hasPermission("MANAGE_MESSAGES"))
- return message.channel. send (missingPermissionsEmbed);
- if(!args[0])
- return message.channel.send (missingArgsEmbed);
- message.channel.bulkDelete(args[0]).then(() => {
- message.channel.send({embed: { color: 0x00AE86,description: `Cleared ${args[0]} messages.`}}).then(msg => msg.delete(5000));
- });
- }
- //Addrole
- if(command === "addrole") {
- var embedColor = 16032066; // Change this to change the color of the embeds!
- var missingPermissionsEmbed = new Discord.RichEmbed() // Creates the embed thats sent if the user is missing permissions
- .setColor(embedColor)
- .setAuthor(message.author.username, message.author.avatarURL)
- .setTitle('Insufficient Permissions!')
- .setDescription('You need the `MANAGE_ROLES` permission to use this command!')
- .setTimestamp();
- if (!message.member.hasPermission("MANAGE_ROLES"))
- return message.reply(missingPermissionsEmbed);
- if (args[0] == "help") {
- message.reply("Usage: ``!addrole <user> <role>``");
- return;
- }
- let rMember = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
- if (!rMember) return message.channel.send ({embed: { color: 16007746,description: "Please Mention Someone to give the role" }});
- let role = args.join(" ").slice(22);
- if (!role) return message.reply ({embed: { color:16007746 ,description: "Specify a role!" }});
- let gRole = message.guild.roles.find(`name`, role);
- if (!gRole) return message.reply ({embed: { color:16007746 ,description: "Couldn't find that role." }});
- if(rMember.roles.has(gRole.id)) return message.reply("They already have that role.");
- await(rMember.addRole(gRole.id));
- try {
- await rMember.send ({embed: { color:4387956 ,description: `Congrats, you have been given the role ${gRole.name}`}});
- } catch (e) {
- console.log(e.stack);
- 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.`)
- }
- }
- //delrole
- if(command === "delrole") {
- if (!message.member.hasPermission("MANAGE_ROLES"))
- return message.reply({embed: { color:16007746 ,description:"Sorry, you don't have permissions to use this!" }});
- if(args[0] == "help"){
- message.reply("Usage: !removerole <user> <role>");
- return;
- }
- let rMember = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]);
- if (!rMember) return message.channel.send ({embed: { color: 16007746,description: "Please Mention Someone to give the role" }});
- let role = args.join(" ").slice(22);
- if (!role) return message.reply ({embed: { color:16007746 ,description: "Specify a role!" }});
- let gRole = message.guild.roles.find(`name`, role);
- if (!gRole) return message.reply ({embed: { color:16007746 ,description: "Couldn't find that role." }});
- if(!rMember.roles.has(gRole.id)) return message.reply("They don't have that role.");
- await(rMember.removeRole(gRole.id));
- try{
- await rMember.send(`RIP, you lost the ${gRole.name} role.`)
- }catch(e){
- message.channel.send(`RIP to <@${rMember.id}>, We removed ${gRole.name} from them. We tried to DM them, but their DMs are locked.`)
- }
- }
- //Help
- if(command === "help") {
- let boticon = client.user.displayAvatarURL;
- let helpembed = new Discord.RichEmbed()
- .setTitle("Help")
- .setColor(0x00AE86)
- .setThumbnail(boticon)
- .addField("1. Core", "``ping``, ``help``, ``invite``, ``serverinfo``, ``botinfo``, ``report``")
- .addField("2. Fun", "``say``")
- .addField ("3. Level" , "``profile``, ``points``, ``give``, ``leaderboard``")
- .addField("4. Moderation", "``kick``, ``ban``, ``warn``, ``clear``, ``addrole``, ``delrole``")
- //.addField("NSFW", "``hentai``, ``cosplay``,``asian``");
- message.channel.send(helpembed);
- }
- });
- client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement