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.
- client.on("ready", () => {
- // This event will run if the bot starts, and logs in, successfully.
- console.log("CFW BOT is ready");
- // Example of changing the bot's playing game to something useful. `client.user` is what the
- // docs refer to as the "ClientUser".
- client.user.setActivity("&help | &cfwhelp | NextgenForum", {type: "WATCHING"});
- });
- client.on('guildMemberAdd', member => {
- member.guild.channels.get('439792255365021696').setName(`Total Users: ${member.guild.memberCount}`)
- let humans = member.guild.members.filter(m => !m.user.bot).size;
- member.guild.channels.get('439793088001736725').setName(`Member Count: ${humans}`)
- let bots = member.guild.members.filter(m => m.user.bot).size;
- member.guild.channels.get('439793716052623361').setName(`Bot Count: ${bots}`)
- });
- client.on("guildCreate", guild => {
- // This event triggers when the bot joins a guild.
- console.log(`New guild joined: ${guild.name} (id: ${guild.id}). This guild has ${guild.memberCount} members!`);
- client.user.setActivity("&help | &cfwhelp | NextgenForum", {type: "WATCHING"});
- });
- client.on("guildDelete", guild => {
- // this event triggers when the bot is removed from a guild.
- console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
- client.user.setActivity("&help | &cfwhelp | NextgenForum", {type: "WATCHING"});
- });
- 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 === "ping") {
- // Calculates ping between sending a message and editing it, giving a nice round-trip latency.
- // The second ping is an average latency between the bot and the websocket server (one-way, not round-trip)
- const m = await message.channel.send("Ping?");
- m.edit(`Pong! Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ping)}ms`);
- }
- if(command === "cfwhelp") {
- let sicon = message.guild.iconURL;
- let serverembed = new Discord.RichEmbed()
- .setDescription("CFW BOT SERVICE LIST:")
- .setColor("#00ff00")
- .setThumbnail(sicon)
- .addField("__**Sprx sites**__", "https://extortiondev.com/, https://www.semjases.com/, http://lastteamstanding.uk/, https://www.powersprx.com/" )
- .addField("__**NextgenUpdate**__", "http://www.nextgenupdate.com/" )
- .addField("__**CFW Bo2 Links**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
- .addField("__**COD - Ghost menus**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
- .addField("__**Rebug website**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
- .addField("__**Mw3 - Links**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
- .addField("__**Debug Help**__", "https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/, https://extortiondev.com/" )
- .addField("__**CFW Bot**__", `***#shoutbox No insults or racist - homophobic even for fun - It is strictly forbidden to publish external links NextgenForum Your personal information will be stored in the context of a complaint if necessary Never an administrator or moderator will ask you for your password or other private information.Never send an SMS and & or a call to a suspicious number. This is always a scam with a premium rate number. Failure to comply with these conditions may result in a temporary or permanent ban of the shoutbox A temporary or permanent ban of the account can also take place this necessary Thank you for respecting these rules***`);
- return message.channel.send(serverembed);
- }
- client.on('message', async msg => {
- if (msg.author.id === midi || msg.author.id === "338192747754160138" || msg.member.roles.some(r => ["Logan DJ", "The Music Meister"].includes(r.name))) {
- if (!msg.content.startsWith(config.prefix)) return undefined;
- const args = msg.content.split(' ');
- const searchString = args.slice(1).join(' ');
- var url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
- const serverQueue = queue.get(msg.guild.id);
- let command = msg.content.toLowerCase().split(' ')[0];
- command = command.slice(config.prefix.length)
- if (command === 'play') {
- const voiceChannel = msg.member.voiceChannel;
- if (!voiceChannel) return msg.channel.send('I\'m sorry but you need to be in a voice channel to play music!');
- if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
- const playlist = await youtube.getPlaylist(url);
- const videos = await playlist.getVideos();
- for (const video of Object.values(videos)) {
- const video2 = await youtube.getVideoByID(video.id);
- await handleVideo(video2, msg, voiceChannel, true);
- }
- return msg.channel.send(`β Playlist: **${playlist.title}** has been added to the queue!`);
- } else {
- try {
- var video = await youtube.getVideo(url);
- } catch (error) {
- try {
- var videos = await youtube.searchVideos(searchString, 10);
- let index = 0;
- msg.channel.send(`
- __**Song selection:**__
- ${videos.map(video2 => `**${++index} -** ${video2.title}`).join('\n')}
- Please provide a value to select one of the π results ranging from 1-10.
- `);
- try {
- var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
- maxMatches: 1,
- time: 10000,
- errors: ['time']
- });
- } catch (err) {
- console.error(err);
- return msg.channel.send('No or invalid value entered, cancelling video selection.');
- }
- const videoIndex = parseInt(response.first().content);
- var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
- } catch (err) {
- console.error(err);
- return msg.channel.send('π I could not obtain any search results.');
- }
- }
- return handleVideo(video, msg, voiceChannel);
- }
- }
- if (command === 'fav') {
- var url = favsong[args[1]] ? favsong[args[1]].replace(/<(.+)>/g, '$1') : '';
- console.log(favsong[args[1]]);
- console.log(" ")
- const voiceChannel = msg.member.voiceChannel;
- if (!voiceChannel) return msg.channel.send('I\'m sorry but you need to be in a voice channel to play music!');
- if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
- const playlist = await youtube.getPlaylist(url);
- const videos = await playlist.getVideos();
- for (const video of Object.values(videos)) {
- const video2 = await youtube.getVideoByID(video.id);
- await handleVideo(video2, msg, voiceChannel, true);
- }
- return msg.channel.send(`β Playlist: **${playlist.title}** has been added to the queue!`);
- } else {
- try {
- var video = await youtube.getVideo(url);
- } catch (error) {
- try {
- msg.channel.send(`__**Song selection:**__\nPlease Choose a song on this list from 1-` + favsong.length + "\nSongs");
- var songarnum = 1;
- while (songarnum < favsong.length) {
- msg.channel.send(songarnum + ". " + favsong[songarnum])
- songarnum++
- }
- } catch (err) {
- console.error(err);
- return msg.channel.send('π I could not obtain any search results.');
- }
- }
- return handleVideo(video, msg, voiceChannel);
- }
- } else if (command === 'skip') {
- if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
- if (!serverQueue) return msg.channel.send('There is nothing playing that I could skip for you.');
- serverQueue.connection.dispatcher.end('Skip command has been used!');
- return undefined;
- } else if (command === 'stop') {
- if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
- if (!serverQueue) return msg.channel.send('There is nothing playing that I could stop for you.');
- serverQueue.songs = [];
- serverQueue.connection.dispatcher.end('Stop command has been used!');
- return undefined;
- } else if (command === 'volume' || command === 'vol') {
- if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
- if (!serverQueue) return msg.channel.send('There is nothing playing.');
- if (!args[1]) return msg.channel.send(`The current volume is: **${serverQueue.volume}**`);
- serverQueue.volume = args[1];
- serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
- var volval;
- if (serverQueue.volume == 1) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 2) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 3) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 4) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 5) {
- volval = `βββββ :loud_sound:β `
- }
- msg.channel.send(volval)
- } else if (command === 'np') {
- if (!serverQueue) return msg.channel.send('There is nothing playing.');
- return msg.channel.send(`πΆ Now playing: **${serverQueue.songs[0].title}**`);
- } else if (command === 'queue') {
- if (!serverQueue) return msg.channel.send('There is nothing playing.');
- return msg.channel.send(`
- __**Song queue:**__
- ${serverQueue.songs.map(song => `**-** ${song.title}`).join('\n')}
- **Now playing:** ${serverQueue.songs[0].title}
- `);
- } else if (command === 'pause') {
- if (serverQueue && serverQueue.playing) {
- serverQueue.playing = false;
- serverQueue.connection.dispatcher.pause();
- return msg.channel.send('βΈ Paused the music for you!');
- }
- return msg.channel.send('There is nothing playing.');
- } else if (command === 'resume') {
- if (serverQueue && !serverQueue.playing) {
- serverQueue.playing = true;
- serverQueue.connection.dispatcher.resume();
- return msg.channel.send('βΆ Resumed the music for you!');
- }
- return msg.channel.send('There is nothing playing.');
- }
- return undefined;
- }
- });
- async function handleVideo(video, msg, voiceChannel, playlist = false) {
- const serverQueue = queue.get(msg.guild.id);
- console.log(chalk.red("MOOOOSIK"));
- const song = {
- id: video.id,
- title: Util.escapeMarkdown(video.title),
- url: `https://www.youtube.com/watch?v=${video.id}`
- };
- if (!serverQueue) {
- const queueConstruct = {
- textChannel: msg.channel,
- voiceChannel: voiceChannel,
- connection: null,
- songs: [],
- volume: 5,
- playing: true
- };
- queue.set(msg.guild.id, queueConstruct);
- queueConstruct.songs.push(song);
- try {
- var connection = await voiceChannel.join();
- queueConstruct.connection = connection;
- play(msg.guild, queueConstruct.songs[0]);
- } catch (error) {
- console.error(`I could not join the voice channel: ${error}`);
- queue.delete(msg.guild.id);
- return msg.channel.send(`I could not join the voice channel: ${error}`);
- }
- } else {
- serverQueue.songs.push(song);
- console.log(serverQueue.songs);
- if (playlist) return undefined;
- else return msg.channel.send(`β **${song.title}** has been added to the queue!`);
- }
- return undefined;
- }
- function play(guild, song) {
- const serverQueue = queue.get(guild.id);
- if (!song) {
- serverQueue.voiceChannel.leave();
- queue.delete(guild.id);
- return;
- }
- console.log(serverQueue.songs);
- const dispatcher = serverQueue.connection.playStream(ytdl(song.url)).on('end', reason => {
- if (reason === 'Stream is not generating quickly enough.') console.log(reason);
- else console.log(reason);
- serverQueue.songs.shift();
- play(guild, serverQueue.songs[0]);
- }).on('error', error => console.error(error));
- var volval;
- if (serverQueue.volume == 1) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 2) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 3) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 4) {
- volval = `ββββββ:loud_sound:β `
- }
- if (serverQueue.volume == 5) {
- volval = `βββββ :loud_sound:β `
- }
- dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
- var NowEmbed = new Discord.RichEmbed().setColor("990033")
- .addField(`=========================================================`,`
- Ι΄α΄α΄‘ α΄Κα΄ΚΙͺΙ΄Ι’: **${song.title}**
- :white_circle:βββββββββββββββββββββββββββββββββββββββββββ
- βββ ββ β βΊβΊβ β γγ${volval}β γγ :gear: β ββ
- ========================================================= `)
- .setFooter("Invite Me! Using l.invite")
- .addField("Logans Server","https://discord.gg/6mvvfSm")
- .addField("The Music Setup was taken from","**Logan**: [Invite](https://discordapp.com/oauth2/authorize?client_id=408070424484904960&scope=bot&permissions=2146958591)");
- serverQueue.textChannel.send(NowEmbed);
- }
- if(command === "help") {
- let sicon = message.guild.iconURL;
- let serverembed = new Discord.RichEmbed()
- .setDescription("Commandlist: copy this >> & << for the bot prefix")
- .setColor("#00ff00")
- .setThumbnail(sicon)
- .addField("__**Help**__", "&help")
- .addField("__**Serverinfo**__", "&serverinfo")
- .addField("__**Report**__", "&report")
- .addField("__**Ping**__", "&ping")
- .addField("__**Kick**__", "&kick")
- .addField("__**Ban**__", "&ban")
- .addField("__**Purge**__", "&purge")
- .addField("__**Play**__", "&play")
- .addField("__**Rules in NextgenForum**__", `***No insults or racist - homophobic even for fun - It is strictly forbidden to publish external links NextgenForum Your personal information will be stored in the context of a complaint if necessary Never an administrator or moderator will ask you for your password or other private information.Never send an SMS and & or a call to a suspicious number. This is always a scam with a premium rate number. Failure to comply with these conditions may result in a temporary or permanent ban of the shoutbox A temporary or permanent ban of the account can also take place this necessary Thank you for respecting these rules***`);
- return message.channel.send(serverembed);
- }
- if(command === "serverinfo") {
- let sicon = message.guild.iconURL;
- let serverembed = new Discord.RichEmbed()
- .setDescription("Server Information")
- .setColor("#15f153")
- .setThumbnail(sicon)
- .addField("Server Name", message.guild.name)
- .addField("Created On", message.guild.createdAt)
- .addField("You Joined", message.member.joinedAt)
- .addField("Total Members", message.guild.memberCount);
- return message.channel.send(serverembed);
- }
- if(command === "report"){
- //!report @ned this is the reason
- let rUser = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
- if(!rUser) return message.channel.send("Couldn't find user.");
- let rreason = args.join(" ").slice(22);
- let reportEmbed = new Discord.RichEmbed()
- .setDescription("Reports")
- .setColor("#15f153")
- .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);
- return;
- }
- if(command === "say") {
- // makes the bot say something and delete the message. As an example, it's open to anyone to use.
- // To get the "message" itself we join the `args` back into a string with spaces:
- const sayMessage = args.join(" ");
- // Then we delete the command message (sneaky, right?). The catch just ignores the error with a cute smiley thing.
- message.delete().catch(O_o=>{});
- // And we get the bot to say the thing:
- message.channel.send(sayMessage);
- }
- if(command === "kick") {
- // This command must be limited to mods and admins. In this example we just hardcode the role names.
- // Please read on Array.some() to understand this bit:
- // https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some?
- if(!message.member.roles.some(r=>["Owner"].includes(r.name)) )
- return message.reply("Sorry, you don't have permissions to use this! only Administrator are able to use this functions");
- // Let's first check if we have a member and if we can kick them!
- // message.mentions.members is a collection of people that have been mentioned, as GuildMembers.
- // We can also support getting the member by ID, which would be args[0]
- let member = message.mentions.members.first() || message.guild.members.get(args[0]);
- if(!member)
- return message.reply("Please mention a valid member of this server");
- if(!member.kickable)
- return message.reply("I cannot kick this user! Do they have a higher role? Do I have kick permissions?");
- // slice(1) removes the first part, which here should be the user mention or ID
- // join(' ') takes all the various parts to make it a single string.
- let reason = args.slice(1).join(' ');
- if(!reason) reason = "He need a break he will be back soon";
- // Now, time for a swift kick in the nuts!
- await member.kick(reason)
- .catch(error => message.reply(`Sorry ${message.author} I couldn't kick because of : ${error}`));
- message.reply(`${member.user.tag} has been kicked by ${message.author.tag} because: ${reason}`);
- }
- if(command === "ban") {
- // Most of this command is identical to kick, except that here we'll only let admins do it.
- // In the real world mods could ban too, but this is just an example, right? ;)
- if(!message.member.roles.some(r=>["Administrator"].includes(r.name)) )
- return message.reply("Sorry, you don't have permissions to use this!");
- let member = message.mentions.members.first();
- if(!member)
- return message.reply("Please mention a valid member of this server");
- if(!member.bannable)
- return message.reply("I cannot ban this user! Do they have a higher role? Do I have ban permissions?");
- let reason = args.slice(1).join(' ');
- if(!reason) reason = "No reason provided";
- await member.ban(reason)
- .catch(error => message.reply(`Sorry ${message.author} I couldn't ban because of : ${error}`));
- message.reply(`${member.user.tag} has been banned by ${message.author.tag} because: ${reason}`);
- }
- if(command === "purge") {
- // This command removes all messages from all users in the channel, up to 100.
- // get the delete count, as an actual number.
- const deleteCount = parseInt(args[0], 10);
- // Ooooh nice, combined conditions. <3
- if(!deleteCount || deleteCount < 2 || deleteCount > 100)
- return message.reply("Please provide a number between 2 and 100 for the number of messages to delete");
- // So we get our messages, and delete them. Simple enough, right?
- const fetched = await message.channel.fetchMessages({limit: deleteCount});
- message.channel.bulkDelete(fetched)
- .catch(error => message.reply(`Couldn't delete messages because of: ${error}`));
- }
- });
- const token = process.env.TOKEN;
- client.login(config.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement