Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

1.1.1

Compare
Choose a tag to compare
@twlite twlite released this 01 Mar 11:37
· 2 commits to main since this release

Updates

  • add VoiceManager#leave method
  • add support for converted and unknown stream types
  • refactor VoiceConnection#disconnect to use disconnect
  • add VoiceConnection#destroy (same as VoiceConnection#disconnect of older versions)
  • VoiceConnection#ping now returns udp latency

Documentation

  • add voice receiving example
  • other minor changes

Example

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

Voice Sending

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

Full Changelog: v1.1.0...v1.1.1