Giter VIP home page Giter VIP logo

dartjs's Introduction

DartJS

DartJS is a Discord.js voice framework that aims to provide similar voice interface of Discord.js v12.

Installation

$ npm i --save dartjs

You may need to install encryption library and opus engine as well.

Features

  • supports voice receiving
  • supports voice sending
  • close to discord.js v12 voice api
  • injects nothing to your client or discord.js

Note

Use <Dispatcher>.once instead of <Dispatcher>.on. Since the concept of StreamDispatcher is gone with the voice rewrite, the StreamDispatcher polyfill does not work exactly like discord.js v12 voice. Using .on to handle events may cause the dispatcher to trigger the event multiple times since same dispatcher instance is used throughout the session. Using .once to handle events will only trigger the event once per your music bot session and wont break your code since .once removes the listener immediately after the event is emitted.

Example

Music Bot

const Discord = require("discord.js");
const client = new Discord.Client({
    intents: [
        Discord.Intents.GUILDS,
        Discord.Intents.GUILD_VOICE_STATES,
        Discord.Intents.GUILD_MESSAGES
    ]
});
const { DartVoiceManager } = require("dartjs");
const voiceManager = new DartVoiceManager(client);
const ytdl = require("ytdl-core");

client.on("ready", () => console.log("Bot is online!"));

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

    if (message.content === "!play") {
        voiceManager.join(message.member.voice.channel)
            .then(connection => {
            const dispatcher = connection.play(ytdl("https://www.youtube.com/watch?v=dQw4w9WgXcQ"));
            dispatcher.once("start", () => message.channel.send("Music started!"));
            dispatcher.once("finish", () => {
                message.channel.send("Music finished!");
            });
        });
    }
});

client.login("XXX");

Voice Receiving

const Discord = require("discord.js");
const client = new Discord.Client({
    intents: [
        Discord.Intents.GUILDS,
        Discord.Intents.GUILD_VOICE_STATES,
        Discord.Intents.GUILD_MESSAGES,
        Discord.Intents.GUILD_MEMBERS
    ]
});
const { DartVoiceManager } = require("dartjs");
const voiceManager = new DartVoiceManager(client);
const fs = require("fs");

client.on("ready", () => console.log("Bot is online!"));

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

    if (message.content === "!record") {
        voiceManager.join(message.member.voice.channel)
            .then(connection => {
                const receiver = connection.receiver.createStream(message.member, {
                    mode: "pcm",
                    end: "silence"
                });

                const writer = receiver.pipe(fs.createWriteStream("./recorded.pcm"));

                writer.on("finish", () => {
                    message.channel.send("Finished recording!");
                });
            });
    }
});

client.login("XXX");

See https://github.com/discord-player/voice-recorder-example for a complete voice recorder example.

Smooth Volume

This feature enables smooth volume transition.

This library will attempt to polyfill smooth volume api by default. This can be disabled by setting DARTJS_DISABLE_INJECTION in env.

Example:

// injecting manually
require("dartjs").injectSmoothVolume();

// Set smoothness before playing
dispatcher.play(stream, {
    // use whatever value feels better
    volumeSmoothness: 0.08
});

// setting smoothness on-the-fly
dispatcher.setVolumeSmoothness(0.08)

dartjs's People

Contributors

ehsanfox avatar twlite avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dartjs's Issues

How do you stop (Force Finish) the current playing audio without disconnecting?

I was recently update some of my code in my bot from v12 to v13 and when I stumbled across this package, I was so excited! (Thank you guys sooo much for your hard work!)

The problem I'm currently having though is finding how to end my currently playing audio without disconnecting from the voice channel. Similar to dispatcher.end(). Any suggestions?

bug: finish event emits immediately

I have tried to use it on a bot that is based on Discord.js version 13, but for some reason, the dispatcher emits the "finish" event immediately.

i'm listening for "start", "finish", "error" and "debug" events,
I have the logs of "debug" events here:

from {"status":"buffering","resource":true,"stepTimeout":false}
to {"status":"playing","missedFrames":0,"playbackDuration":0,"resource":true,"stepTimeout":false}

No outputs from "error" events though.

The stream is also coming directly from ytdl-core (as it is in the example),
Here is my PlayOptions object:

{
     metadata: {
           ctx,
           track,
           connection
     },
     behaviours: {
           noSubscriber: NoSubscriberBehavior.Stop
     },
          inlineVolume: true,
          initialVolume: 100 / 100
}

any idea or any solution?

Support

Hi! I have some doubts with the package and I wanted to know if you have a group that takes them out.

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.