Giter Club home page Giter Club logo

ruvyrias's Introduction

Note: This version supports only Lavalink V4 or above.

npm GitHub issues NPM

Ruvyrias NPM Package

Table of contents

Installation

# Using npm
npm install ruvyrias

# Using yarn
yarn add ruvyrias

About

To use, you need a configured Lavalink instance.

Ruvyrias is a robust Discord music bot client tailored for Lavalink V4 and above. Key features include:

  • Stability: A reliable and smooth client experience.
  • TypeScript Support: Enhanced development with TypeScript.
  • Lavalink Compatibility: 100% compatible with Lavalink version 4 and above.
  • Object-Oriented: Organized and maintainable code.
  • Customizable: Adapt the client to your bot preferences.
  • Easy Setup: Quick and hassle-free installation.
  • Queue System: Efficiently manage music playback.
  • Platform Support: Built-in compatibility with Youtube, Soundcloud, Spotify, Apple Music, and Deezer.

Implementation Repositories

Note: Send PR to add your repository here.

Repository Creator Additional Information
Ruvyrias Example DarkslayerHaos Official Ruvyrias Exampe Bot, easy setup and usage.
Lunox adh319 Check out the repository for futher information.

Basic Usage

// Import necessary modules.
const { Client, GatewayIntentBits, ActivityType } = require('discord.js');
const { Ruvyrias } = require('ruvyrias');

// Define Lavalink nodes configuration.
const nodes = [
    {
        name: 'main',
        host: 'localhost',
        port: 2333,
        password: 'youshallnotpass',
        secure: false,
        resume: true,
    },
];

// Define options for Ruvyrias client.
const RuvyriasOptions = {
    library: 'discord.js',
    defaultPlatform: 'ytsearch',
    autoResume: true,
    reconnectTries: Infinity,
    reconnectTimeout: 1000 * 10,
};

// Initialize Discord client with necessary intents.
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.MessageContent,
    ],
});

// Create Ruvyrias instance and bind it to the client.
client.ruvyrias = new Ruvyrias(client, nodes, RuvyriasOptions);

// Event handler for when the bot is ready.
client.on('ready', client => {
    console.log(`[+] Logged in as: ${client.user?.tag}`);
    client.ruvyrias.init(client);

    client.user.setActivity({ name: '!play', type: ActivityType.Listening });
});

// Event handler for message creation.
client.on('messageCreate', async message => {
    // Ignore messages that don't start with '!' or are from bots.
    if (!message.content.toLowerCase().startsWith('!') || message.author.bot) return;

    // Extract command and arguments from the message
    const args = message.content.slice(1).trim().split(/ +/g);
    const command = args.shift()?.toLowerCase();

    if (command === 'play') {
        const query = args.join(' ');

        // Creating the Player.
        const player = client.ruvyrias.createConnection({
            guildId: message.guildId,
            voiceChannel: message.member.voice.channel.id,
            textChannel: message.channelId,
            deaf: true,
            mute: false,
        });

        const resolve = await client.ruvyrias.resolve({ query, requester: message.author });
        const { loadType, tracks, playlistInfo } = resolve;

        // Handle errors or empty responses.
        if (loadType === 'error' || loadType === 'empty') {
            return message.reply({
                embeds: [
                    { description: `โŒ An error occurred, please try again!`, color: Colors.Red },
                ],
            });
        }

        // Handle playlist loading.
        if (loadType === 'playlist') {
            for (const track of tracks) {
                player.queue.add(track);
            }

            if (!player.playing && !player.paused) return player.play();
            return message.reply(
                `๐ŸŽถ [${playlistInfo?.name}](${query}) with \`${tracks.length}\` tracks added.`
            );
        }
        // Handle single track or search results loading.
        else if (loadType === 'search' || loadType === 'track') {
            const track = tracks[0];
            player.queue.add(track);

            if (!player.playing && !player.paused) return player.play();
            return message.channel.send(`๐ŸŽถ \`${track.info.title}\` added to queue.`);
        }
    }
});

// Runs when a Lavalink Node is successfully connected.
client.ruvyrias.on('nodeConnect', node => {
    console.log(`[+] Node ${node.options.name} connected.`);
});

// Runs when a new track starts playing in the music player.
client.ruvyrias.on('trackStart', (player, track) => {
    const channel = client.channels.cache.get(player.textChannel);

    channel.send(`๐ŸŽถ Now playing: \`${track.info.title}\` by \`${track.info.author}\`.`);
});

// Runs when the music playlist reaches the end and the music player leaves the voice channel.
client.ruvyrias.on('queueEnd', player => {
    player.stop();

    const channel = client.channels.cache.get(player.textChannel);
    channel.send("โ›” The player queue has ended, i'm leaving voice channal!");
});

// Log in the bot using the provided token.
client.login('token');

Credits

The Ruvyrias client, customized by DarkslayerHaos, is a fork originally derived from the code of Poru developed by Parasop.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.