1.1.3 • Published 2 years ago

blackcat-music v1.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

BlackCat-music

sử dụng music bot discord v14 cực kỳ đơn giản với BlackCat-music dành cho những bạn mới làm quen với code bot discord

Các phụ thuộc:

  • blackcat-club: v1.2...
const { discord: { Client, ... }, DjsVoice: { AudioPlayerStatus, ... }} = require("blackcat-club");
  • @distube/soundcloud: v1.2.1
const { soundcloud: { SoundCloudPlugin }} = require("blackcat-music");
  • @distube/spotify: v1.3.2
const { spotify: { SpotifyPlugin }} = require("blackcat-music");
  • @distube/yt-dlp: v1.1.3
const { ytdlp: { YtDlpPlugin }} = require("blackcat-music");
  • distube: v4.0.3
const { distube: { Distube }} = require("blackcat-music");
const { Client_BlackCat, Discord: { Client }} = require('blackcat-club');
const client = new Client(Client_BlackCat());
const { 
  distube: { DisTube },
  spotify: { SpotifyPlugin },
  ytdlp: { YtDlpPlugin },
  soundcloud: { SoundCloudPlugin }
} = require("blackcat-music");
/***
 *** client = Discord.Client
***/
const blackcat_music = new DisTube(client, {
	searchSongs: 0,
	searchCooldown: 30,
	leaveOnEmpty: true,
	emptyCooldown: 25,
  savePreviousSongs: true, 
	leaveOnFinish: false,
	leaveOnStop: false,
	nsfw: true,
	plugins: [
        new SpotifyPlugin({ 
            parallel: true, 
            emitEventsAfterFetching: true,
            api: {
              clientId: " clientId Spotify", 
              clientSecret: "clientSecret Spotify"
            }
        }),
        new SoundCloudPlugin(),
        new YtDlpPlugin({ update: true })
    ],
    youtubeCookie: "youtube Cookie",
    ytdlOptions: {
        highWaterMark: 1024 * 1024 * 64,
        quality: "highestaudio",
        format: "audioonly",
        liveBuffer: 60000,
        dlChunkSize: 1024 * 1024 * 4,
        youtubeCookie: "youtube Cookie"
    },
    emitAddListWhenCreatingQueue: true,
    emitAddSongWhenCreatingQueue: false,
    emitNewSongOnly: true,
});
/**
  * Bot Ready
**/
client.on('ready', client => {
	console.log(`Logged in as ${client.user.tag}!`);
});
/**
  * config data
**/
const config = {
	prefix: ' You prefix ',
	token: " you token ",
};
client.login(config.token)
// client.on("debug", console.log)
client.on('messageCreate', message => {
	if (message.author.bot || !message.inGuild()) return;
	if (!message.content.startsWith(config.prefix)) return;
	const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
	const command = args.shift();
	if (command === 'play') {
		const voiceChannel = message.member?.voice?.channel;
		if (voiceChannel) {
			distube.play(voiceChannel, args.join(' '), {
				message,
				textChannel: message.channel,
				member: message.member,
			});
		} else {
			message.channel.send('You must join a voice channel first.');
		};
	};
	if (['repeat', 'loop'].includes(command)) {
		const mode = distube.setRepeatMode(message);
		message.channel.send(`Set repeat mode to \`${mode ? mode === 2	? 'All Queue'	: 'This Song'	: 'Off'}\``);
	};
	if (command === 'stop') {
		distube.stop(message);
		message.channel.send('Stopped the music!');
	};
	if (command === 'leave') {
		distube.voices.get(message)?.leave();
		message.channel.send('Leaved the voice channel!');
	};
	if (command === 'resume') distube.resume(message);
	if (command === 'pause') distube.pause(message);
	if (command === 'skip') distube.skip(message);
	if (command === 'queue') {
		const queue = distube.getQueue(message);
		if (!queue) {
			message.channel.send('Nothing playing right now!');
		} else {
			message.channel.send(`Current queue:\n${queue.songs.map((song, id) => `**${id ? id : 'Playing'}**. ${song.name} - \`${song.formattedDuration}\``).slice(0, 10).join('\n')}`);
		};
	};
	if ([
			'3d',
			'bassboost',
			'echo',
			'karaoke',
			'nightcore',
			'vaporwave',
		].includes(command)) {
		const filter = distube.setFilter(message, command);
		message.channel.send(`Current queue filter: ${filter.join(', ') || 'Off'}`);
	};
});

// Queue status template
const status = queue => `Volume: \`${queue.volume}%\` | Filter: \`${queue.filters.join(', ') || 'Off'}\` | Loop: \`${ queue.repeatMode ? queue.repeatMode === 2 ? 'All Queue'	: 'This Song'	: 'Off'}\` | Autoplay: \`${queue.autoplay ? 'On' : 'Off'}\``;
  // events music
  blackcat_music.on('playSong', (queue, song) => {
		queue.textChannel?.send(`Playing \`${song.name}\` - \`${song.formattedDuration}\`\nRequested by: ${song.user}\n${status(queue)}`),
  })
	.on('addSong', (queue, song) => {
		queue.textChannel?.send(`Added ${song.name} - \`${song.formattedDuration}\` to the queue by ${song.user}`)
  })
	.on('addList', (queue, playlist) => {
		queue.textChannel?.send(`Added \`${playlist.name}\` playlist (${playlist.songs.length} songs) to queue\n${status(queue)}`),
  })
	.on('error', (textChannel, e) => {
		console.error(e);
		textChannel.send(`An error encountered: ${e.message.slice(0, 2000)}`);
	})
	.on('finish', queue => queue.textChannel?.send('Finish queue!'))
	.on('finishSong', queue => {
		queue.textChannel?.send('Finish song!'),
  })
	.on('disconnect', queue => {
		queue.textChannel?.send('Disconnected!'),
  })
	.on('empty', queue => {
		queue.textChannel?.send('The voice channel is empty! Leaving the voice channel...'),
  })
	// DisTubeOptions.searchSongs > 1
	.on('searchResult', (message, result) => {
		let i = 0;
		message.channel.send(`**Choose an option from below**\n${result.map(song => `**${++i}**. ${song.name} - \`${song.formattedDuration}\``,).join('\n',)}\n*Enter anything else or wait 30 seconds to cancel*`);
	 })
	.on('searchCancel', (message) => {
		message.channel.send('Searching canceled')
    })
	.on('searchInvalidAnswer', message => {
		message.channel.send('Invalid number of result.')
    })
	.on('searchNoResult', message => {
		message.channel.send('No result found!')
   })
	.on('searchDone', () => {});

bạn có thể thiết kế bot theo ý thích của mình

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago