@discord-ts/music
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

About

@discord-ts/music is a Node.js module for music streaming for Discords bot.

Installation

Node.js 16.6.0 or newer is required.

npm

npm install discord.js @discord-ts/music

yarn

yarn add discord.js @discord-ts/music

npm

pnpm add discord.js @discord-ts/music

Example

import { Client } from "discord.js";
import { Player, PlayerGuild, Track, InvalidQueryError, EmptyListError } from "@discord-ts/music";

const bot = new Client({
    intents: ["GUILD_VOICE_STATES", "GUILDS"]
});

const player = new Player({ idle: 300 });

/* COMMAND REGISTRATION */

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

bot.on("interactionCreate", async (interaction) => {
    if (!interaction.isCommand())
        return;

    if (interaction.commandName === "play") {
        const query = interaction.options.getString("query", true);

        if (!interaction.member.voice.channel) {
            return await interaction.reply("Not connected in a voice channel.");
        }

        try {
            await player.play(interaction.member.voice.channel, query);
        } catch (error) {
            if (error instanceof InvalidQueryError) {
                return await interaction.reply(error.message);
            }

            if (error instanceof EmptyListError) {
                return await interaction.reply(error.message);
            }
        }
    }
});

player.on("start", (playerGuild: PlayerGuild, track: Track) => {
    const channel = playerGuild.guild.channels.cache.filter(channel => channel.isText()).first();

    if (!channel) {
        return;
    }

    channel.send(`The bot is now reproducing ${track.title}!`);
});

player.on("trackCreate", (playerGuild: PlayerGuild, track: Track) => {
    const channel = playerGuild.guild.channels.cache.filter(channel => channel.isText()).first();

    if (!channel) {
        return;
    }

    channel.send(`${track.title} has been added to the queue!`);
});

bot.login("token");

Links

Package Sidebar

Install

npm i @discord-ts/music

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

45.4 kB

Total Files

37

Last publish

Collaborators

  • danieleguglietti