Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Load up the discord.js library
- const Discord = require("discord.js");
- // This is your client. Some people call it `bot`, some people call it `self`,
- // some might call it `cootchie`. Either way, when you see `client.something`, or `bot.something`,
- // this is what we're refering to. Your client.
- const client = new Discord.Client();
- // Here we load the config.json file that contains our token and our prefix values.
- const config = require("./config.json");
- // config.token contains the bot's token
- // config.prefix contains the message prefix.
- const prefix = "."
- client.on("ready", () => {
- // This event will run if the bot starts, and logs in, successfully.
- console.log(`logged in as ${client.user.tag}`);
- // Example of changing the bot's playing game to something useful. `client.user` is what the
- // docs refer to as the "ClientUser".
- client.user.setPresence({
- game: {
- name: `helping over ${client.guilds.size} servers!`,
- type: "streaming",
- url: "https://www.twitch.tv/monstercat"
- }
- });
- const delay = (msec) => new Promise((resolve) => setTimeout(resolve, msec));
- client.on("message", async message => {
- // This event will run on every single message received, from any channel or DM.
- // It's good practice to ignore other bots. This also makes your bot ignore itself
- // and not get into a spam loop (we call that "botception").
- if (message.author.bot) return;
- // Also good practice to ignore any message that does not start with our prefix,
- // which is set in the configuration file.
- if (message.content.indexOf(config.prefix) !== 0) return;
- // Here we separate our "command" name, and our "arguments" for the command.
- // e.g. if we have the message "+say Is this the real life?" , we'll get the following:
- // command = say
- // args = ["Is", "this", "the", "real", "life?"]
- const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- // Let's go with a few common example commands! Feel free to delete or change those.
- if (command === "ban") {
- if(!message.guild.me.hasPermission("BAN_MEMBERS")) return message.react('❌'), message.channel.send('I don\'t have permissions to ban members. please contact a server admin')
- if (!message.member.hasPermission("BAN_MEMBERS")) return message.react('❌'), message.channel.send('Sorry, but you don\'t have permission to ban members.')
- let member = message.mentions.members.first()
- if (!member) return message.react('❌'), message.channel.send('Hey! you didn\'t mention a user.')
- if (!member.bannable)
- return message.react('❌'), message.channel.send('Sorry, but i cannot ban that user.')
- let reason = args.slice(1).join(' ');
- if (!reason) reason = "no reason provided."
- member.send(`Hey, mate you\'ve been banned in ${message.guild.name} by ${message.author.tag} because: "${reason}" 🇫`);
- await delay(100); // 100 msec = 0.1 seconds
- member.ban(reason)
- message.channel.send(`${member} was successfully banned by ${message.author.tag} for: "${reason}", can we get a f in the chat?`)
- message.react('🇫'), message.react('✅')
- }
- if (command === "kick") {
- if(!message.guild.me.hasPermission("KICK_MEMBERS")) return message.react('❌'), message.channel.send('I don\'t have permissions to kick members. please contact a server admin')
- if (!message.member.hasPermission("KICK_MEMBERS")) return message.react('❌'), message.channel.send('Sorry, but you don\'t have permission to kick members.')
- let member = message.mentions.members.first()
- if (!member) return message.react('❌'), message.channel.send('please provide a user to kick.')
- if (!member.kickable)
- return message.react('❌'), message.channel.send('I cannot ban that user. they could be a admin, be higher than me, etc.')
- let reason = args.slice(1).join(' ');
- if (!reason) reason = "no reason provided."
- member.send(`Hey, mate you\'ve been kicked in ${message.guild.name} by ${message.author.tag} because: "${reason}" 🇫`);
- await delay(500); // 100 msec = 0.1 seconds
- member.kick(reason)
- message.channel.send(`${member} was successfully kicked by ${message.author.tag} for: "${reason}", can we get a f in the chat?`)
- message.react('🇫'), message.react('✅')
- }
- });
- });
- client.login(config.token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement