Socket
Socket
Sign inDemoInstall

discord-temp-channels

Package Overview
Dependencies
0
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    discord-temp-channels

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


Version published
Weekly downloads
41
decreased by-25.45%
Maintainers
1
Install size
22.4 kB
Created
Weekly downloads
 

Readme

Source

Discord Temporary Voice Channels

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

Installation

npm install --save discord-temp-channels

Example

Code

const Discord = require("discord.js");
const client = new Discord.Client();

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

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("message", (message) => {

    if(message.content.startsWith("!set")){
        if(tempChannels.channels.some((channel) => channel.channelID === message.member.voice.channel.id)){
            return message.channel.send("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("Your voice is now a main voice channel!");
    }

});

client.login("YOUR_TOKEN");

FAQs

Last updated on 04 Feb 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc