npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@universenl/discord-temp-channels

v1.0.4

Published

Simple framework to facilitate the creation of a temporary voice channels system using Discord.js

Downloads

6

Readme

Discord Temporary Voice Channels

Discord Temp Channels is a framework to facilitate the creation of a temporary voice channels system using Discord.js (v14)!

Installation

npm install --save discord-temp-channels

Example

Code

const Discord = require("discord.js");
const client = new Discord.Client({ intents: [
    Discord.GatewayIntentBits.Guilds,
    Discord.GatewayIntentBits.GuildMessages,
    Discord.GatewayIntentBits.GuildVoiceStates,
    Discord.GatewayIntentBits.MessageContent
]});

const TempChannels = require("discord-temp-channels");
const tempChannels = new TempChannels(client);

// Register a new main channel
tempChannels.registerChannel("channel-id", {
    childCategory: "category-id",
    childAutoDeleteIfEmpty: true,
    childMaxUsers: 3,
    childFormat: (member, count) => `#${count} | ${member.user.username}'s lounge`
});

client.login("YOUR_TOKEN");

Result

temp

Methods

Register Channel

You have to register a channel to indicate to the package which channel will be used to create child channels.

// Register a new parent channel
tempChannels.registerChannel("channel-id", {
    childCategory: "category-id",
    childAutoDeleteIfEmpty: true,
    childAutoDeleteIfOwnerLeaves: true,
    childMaxUsers: 3,
    childBitrate: 64000,
    childFormat: (member, count) => `#${count} | ${member.user.username}'s lounge`
});

channelID: The ID of the channel the users will have to join to create a new channel.

options.childCategory: Optional - This will be the category ID in which the new channels will be created.
options.childAutoDeleteIfEmpty: Whether, when a channel is empty, it should be deleted.
options.childAutoDeleteIfOwnerLeaves: Whether, when the member who created a channel left it, it should be deleted (even if it's not empty).
options.childMaxUsers: Optional - This will be the maximum number of users that can join a channel
options.childBitrate: Optional - This will be the new channel bitrate
options.childFormat: This is a function which takes two parameters: the member (the one who created the channel, and the number of voice channels created from the same parent channel)

Un-Register Channel

You can un-register a channel, so the users who join the it won't create a new channel.

// Unregister a parent channel
tempChannels.unregisterChannel("channel-id");

channelID: The ID of the channel you want unregister.

Events

// Emitted when a child channel is created
tempChannels.on("childCreate", (member, channel, parentChannel) => {
    console.log(member); // The member who created the new channel
    console.log(channel); // The channel which was created
    console.log(parentChannel); // The channel the member joined to create the new channel
});

// Emitted when a child channel is deleted
tempChannels.on("childDelete", (member, channel, parentChannel) => {
    console.log(member); // The member who caused the deletion of the channel
    console.log(channel); // The channel which was deleted
    console.log(parentChannel); // The channel the member joined to create the deleted channel
});

// Emitted when a channels is registered
tempChannels.on("channelRegister", (channelData) => {
    console.log(channelData);
    /*
    {
        "channelID": "03909309383083"
        "options": {
            "childCategory": "380398303838398390",
            "childAutoDeleteIfEmpty": true
            etc...
        }
    }
    */
});

// Emitted when a channels is unregistered
tempChannels.on("channelUnregister", (channelData) => {
    console.log(channelData);
    /*
    {
        "channelID": "03909309383083"
        "options": {
            "childCategory": "380398303838398390",
            "childAutoDeleteIfEmpty": true
            etc...
        }
    }
    */
});

// Emitted when there is an error
tempChannels.on("error", (err, message) => {
    console.log(err);
    console.log(message);
});

Bot Example

This code stores temporary channels data in a database (quick.db in this case). When the bot starts, it registers all the channels in the database and there is a command to add new main channels (!set).

const Discord = require("discord.js");
const client = new Discord.Client({ intents: [
    Discord.GatewayIntentBits.Guilds,
    Discord.GatewayIntentBits.GuildMessages,
    Discord.GatewayIntentBits.GuildVoiceStates,
    Discord.GatewayIntentBits.MessageContent
]});

const TempChannels = require("discord-temp-channels");
const tempChannels = new TempChannels(client);

const db = require("quick.db");

client.on("ready", () => {
    if (!db.get("temp-channels")) db.set("temp-channels", []);
    db.get("temp-channels").forEach((channelData) => {
        tempChannels.registerChannel(channelData.channelID, channelData.options);
    });
});

client.on("messageCreate", (message) => {

    if(message.content.startsWith("!set")){
        if(tempChannels.channels.some((channel) => channel.channelID === message.member.voice.channel.id)){
            return message.channel.send({ content: "Your voice channel is already a main voice channel" });
        }
        const options = {
            childAutoDeleteIfEmpty: true,
            childAutoDeleteIfOwnerLeaves: true,
            childMaxUsers: 3,
            childBitrate: 64000,
            childFormat: (member, count) => `#${count} | ${member.user.username}'s lounge`
        };
        tempChannels.registerChannel(message.member.voice.channel.id, options);
        db.push("temp-channels", {
            channelID: message.member.voice.channel.id,
            options: options
        });
        message.channel.send({ content: "Your voice is now a main voice channel!" });
    }

});

client.login("YOUR_TOKEN");