Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

csn-music

icytea243ISC3.2.31TypeScript support: included

A music library to be used with discord.js to create music bots.

csn, music

readme

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");