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 ytdl = require('ytdl-core');
- const request = require('request');
- const fs = require('fs');
- const getYoutubeID = require('get-youtube-id');
- const fetchVideoInfo = require('youtube-info');
- const yt_api_key = "AIzaSyDeoIH0u1e72AtfpwSKKOSy3IPp2UHzqi4";
- const prefix = '!';
- const discord_token = "NTAxNDE3MTA1NjkwNzIyMzA0.DqZEsg.kk6pgIuQzA4LRcSZTGbGg8FOg1E";
- client.login(discord_token);
- client.on('ready', function() {
- console.log(`i am ready ${client.user.username}`);
- });
- /*
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- */
- var servers = [];
- var queue = [];
- var guilds = [];
- var queueNames = [];
- var isPlaying = false;
- var dispatcher = null;
- var voiceChannel = null;
- var skipReq = 0;
- var skippers = [];
- var now_playing = [];
- /*
- \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
- \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
- \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
- \\\\\\\\\\\\\\\\\\\\\\\\V/////////////////////////
- */
- client.on('ready', () => {
- client.user.setPresence({
- game: {
- name: '!play or !skip',
- type: 0
- }
- });
- });
- var download = function(uri, filename, callback) {
- request.head(uri, function(err, res, body) {
- console.log('content-type:', res.headers['content-type']);
- console.log('content-length:', res.headers['content-length']);
- request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
- });
- };
- client.on('message', async message => {
- const member = message.member;
- const mess = message.content.toLowerCase();
- const args = message.content.split(' ').slice(1).join(' ');
- if (mess.startsWith(prefix + 'play')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- // if user is not insert the URL or song title
- if (args.length == 0) {
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .setFooter('طلب بواسطة: ' + message.author.tag)
- .setDescription('**قم بإدراج رابط او اسم الأغنيه**')
- message.channel.sendEmbed(play_info)
- return;
- }
- if (queue.length > 0 || isPlaying) {
- getID(args, function(id) {
- add_to_queue(id);
- fetchVideoInfo(id, function(err, videoInfo) {
- if (err) throw new Error(err);
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .addField('تمت إضافةالاغنيه بقائمة الإنتظار', `**
- ${videoInfo.title}
- **`)
- .setColor("#a637f9")
- .setFooter('|| ' + message.author.tag)
- .setThumbnail(videoInfo.thumbnailUrl)
- message.channel.sendEmbed(play_info);
- queueNames.push(videoInfo.title);
- now_playing.push(videoInfo.title);
- });
- });
- }
- else {
- isPlaying = true;
- getID(args, async function(id) {
- queue.push('placeholder');
- playMusic(id, message);
- fetchVideoInfo(id, async function(err, videoInfo) {
- if (err) throw new Error(err);
- const msg = await message.channel.send(`**Searching for "${args}"**`);
- msg.edit(`**Now Playing: "${videoInfo.title}"**`);
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- });
- });
- }
- }
- else if (mess.startsWith(prefix + 'skip')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- message.channel.send('`✔`').then(() => {
- skip_song(message);
- var server = server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- });
- }
- else if (message.content.startsWith(prefix + 'vol')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- // console.log(args)
- if (args > 100) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
- if (args < 1) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
- dispatcher.setVolume(1 * args / 50);
- message.channel.sendMessage(`**__ ${dispatcher.volume*50}% مستوى الصوت __**`);
- }
- else if (mess.startsWith(prefix + 'pause')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- message.channel.send('`✔`').then(() => {
- dispatcher.pause();
- });
- }
- else if (mess.startsWith(prefix + 'ok')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- message.channel.send('`✔`').then(() => {
- dispatcher.resume();
- });
- }
- else if (mess.startsWith(prefix + 'stop')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- message.channel.send('`✔`');
- var server = server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- }
- else if (mess.startsWith(prefix + 'تعال')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- message.member.voiceChannel.join().then(message.channel.send(':ok:'));
- }
- else if (mess.startsWith(prefix + 'play')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- if (isPlaying == false) return message.channel.send(':anger: || **__تم التوقيف__**');
- let playing_now_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .addField('تمت إضافةالاغنيه بقائمة الإنتظار', `**
- ${videoInfo.title}
- **`)
- .setColor("RANDOM")
- .setFooter('طلب بواسطة: ' + message.author.tag)
- .setThumbnail(videoInfo.thumbnailUrl)
- //.setDescription('?')
- message.channel.sendEmbed(playing_now_info);
- }
- });
- function skip_song(message) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- dispatcher.end();
- }
- function playMusic(id, message) {
- voiceChannel = message.member.voiceChannel;
- voiceChannel.join().then(function(connectoin) {
- let stream = ytdl('https://www.youtube.com/watch?v=' + id, {
- filter: 'audioonly'
- });
- skipReq = 0;
- skippers = [];
- dispatcher = connectoin.playStream(stream);
- dispatcher.on('end', function() {
- skipReq = 0;
- skippers = [];
- queue.shift();
- queueNames.shift();
- if (queue.length === 0) {
- queue = [];
- queueNames = [];
- isPlaying = false;
- }
- else {
- setTimeout(function() {
- playMusic(queue[0], message);
- }, 500);
- }
- });
- });
- }
- function getID(str, cb) {
- if (isYoutube(str)) {
- cb(getYoutubeID(str));
- }
- else {
- search_video(str, function(id) {
- cb(id);
- });
- }
- }
- function add_to_queue(strID) {
- if (isYoutube(strID)) {
- queue.push(getYoutubeID(strID));
- }
- else {
- queue.push(strID);
- }
- }
- function search_video(query, cb) {
- request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
- var json = JSON.parse(body);
- cb(json.items[0].id.videoId);
- });
- }
- function isYoutube(str) {
- return str.toLowerCase().indexOf('youtube.com') > -1;
- }
- client.on('message', message => {
- if (message.content === prefix +"help") {
- const embed = new Discord.RichEmbed()
- .setColor("RANDOM")
- .addField(`Zyad,aLmutairi commands:
- +about - shows info about the bot
- +ping - checks the bot's latency
- Music:
- +play - shows the song that is currently playing
- +play <title|URL|subcommand> - plays the provided song
- +queue [pagenum] - shows the current queue
- +تعال <title|URL|subcommand> - plays the provided song
- +skip - votes to skip the current song
- DJ:
- +ok <title|URL|subcommand> - plays the provided song
- +skip - skips the current song
- +pause - pauses the current song
- +skipt <position> - skips to the specified song
- +stop - stops the current song and clears the queue
- +vol [0-150] - sets or shows volume
- For additional help, `)
- message.channel.send({embed});
- }
- });
- client.on('message', message => {
- if (message.content.startsWith("habout")) {
- message.channel.send({
- embed: new Discord.RichEmbed()
- .setColor('RED')
- .addField('**الذاكرة المستخدمة 💾**', `${(process.memoryUsage().rss / 1000000).toFixed()}MB`, true)
- .addField('**سرعة الاتصال📡**' , `${Date.now() - message.createdTimestamp}` + ' ms')
- .addField('**وقت الاقلاع⌚**', timeCon(process.uptime()), true)
- .addField('**استخدام المعالج💿**', `${(process.cpuUsage().rss / 10000).toFixed()}%`, true)
- })
- }
- });
- client.on('message', message => {
- if(!message.channel.guild) return;
- if (message.content.startsWith('hping')) {
- if(!message.channel.guild) return;
- var msg = `${Date.now() - message.createdTimestamp}`
- var api = `${Math.round(client.ping)}`
- if (message.author.bot) return;
- let embed = new Discord.RichEmbed()
- .setAuthor(message.author.username,message.author.avatarURL)
- .setColor('RANDOM')
- .addField('**Time Taken:**',msg + " ms 📶 ")
- .addField('**WebSocket:**',api + " ms 📶 ")
- message.channel.send({embed:embed});
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement