csn-music
TypeScript icon, indicating that this package has built-in type declarations

3.2.31 • Public • Published

About

csn-music is a music module that helps you to play music from chiasenhac.vn.

Installation

Node.js 16.9.0 or newer is required.

npm install csn-music

Basic Usage

const CSNClient = require("csn-music");
const Discord = require("discord.js");

const client = new Discord.Client({
	intents: 32767,
});

const csn = new CSNClient(client);

client.on("ready", () => {
	console.log(`Logged in as ${client.user.tag}!`);

	csn.on("playSong", async (player, song) => {
		await player.textChannel.send({
			embeds: [
				new Discord.EmbedBuilder().setDescription(`Now playing: ${song.title}`),
			],
		});
	});
});

client.on("messageCreate", async (message) => {
	if (message.author.bot) return;
	if (!message.content) return;

	if (message.content.startsWith("!")) {
		const args = message.content.split(/[ ]+/g);
		const commandName = args.shift().toLowerCase();

		if (commandName === "play") {
			const query = args.join(" ");
			const voiceChannel = message.member.voice.channel;

			if (!voiceChannel)
				return message.reply(
					"You need to be in a voice channel to play music."
				);

			const searches = await csn.search({
				name: query,
				limit: 5,
				searchType: "music",
				requester: message.author,
			});

			let player;

			if (csn.getPlayer(message.guild.id))
				player = csn.getPlayer(message.guild.id);
			else
				player = await csn.createPlayer({
					voiceChannel,
					textChannel: message.channel,
					guild: message.guild,
				});

			player.addToQueue(searches[0]);

			const { title, url, thumbnail } = searches[0];

			return message.reply(`Added ${title} to the queue.`);

			if (!player.isPlaying && !player.isPaused) player.play();
		} else if (commandName === "pause") {
			const player = csn.getPlayer(message.guild.id);

			if (!player) return await message.channel.send("No player found.");

			player.pause();

			return await message.channel.send("Paused.");
		} else if (commandName === "resume") {
			const player = csn.getPlayer(message.guild.id);

			if (!player) return await message.channel.send("No player found.");

			player.resume();

			return await message.channel.send("Resumed.");
		} else if (commandName === "stop") {
			const player = csn.getPlayer(message.guild.id);

			if (!player) return await message.channel.send("No player found.");

			player.destroy();

			return await message.channel.send("Stopped.");
		}
	}
});

client.login("token");

Readme

Keywords

Package Sidebar

Install

npm i csn-music

Weekly Downloads

69

Version

3.2.31

License

ISC

Unpacked Size

38.9 kB

Total Files

15

Last publish

Collaborators

  • icytea