trixxy-tempvoice
v1.0.0
Published
A package for managing temporary Discord voice channels.
Maintainers
Readme
trixxy-tempvoice
A Discord.js package for managing temporary voice channels.
Installation
npm install trixxy-tempvoiceDependencies
This package relies on discord.js.
Setup in Discord
Before using this package, you need to set up your Discord server:
- Create a Category Channel: Create a new category channel named
Temporary Voice Channels(or any name you prefer, but remember to update the code if you change it). - Create a "Join to Create" Voice Channel: Inside the
Temporary Voice Channelscategory, create a voice channel (e.g.,➕ Create Channel). This will be the channel users join to automatically create their temporary voice channel.
Usage
Here's how to use the TrixxyTempVoice class in your Discord bot:
const { Client, GatewayIntentBits } = require('discord.js');
const TrixxyTempVoice = require('trixxy-tempvoice');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates, // Required for voice state updates
],
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
const tempVoiceManager = new TrixxyTempVoice(client);
// Replace 'YOUR_GUILD_ID' with your server's ID
// Replace 'YOUR_JOIN_TO_CREATE_CHANNEL_ID' with the ID of your "Join to Create" voice channel
tempVoiceManager.setJoinToCreateChannel('YOUR_GUILD_ID', 'YOUR_JOIN_TO_CREATE_CHANNEL_ID');
});
client.login('YOUR_BOT_TOKEN');TrixxyTempVoice Class Methods
constructor(client)
Initializes the temporary voice channel manager.
client: An instance ofdiscord.js.Client.
setJoinToCreateChannel(guildId, channelId)
Configures a specific voice channel to act as a "join-to-create" channel within a guild. When a user joins this channelId, a new temporary voice channel will be created for them.
guildId: The ID of the Discord guild (server).channelId: The ID of the voice channel that users will join to trigger the creation of a temporary channel.
handleVoiceStateUpdate(oldState, newState) (Private Method)
This method is an internal event listener for voiceStateUpdate. It detects when users join or leave voice channels and triggers the creation or deletion of temporary channels accordingly.
createTemporaryChannel(member) (Private Method)
Creates a new temporary voice channel for the given GuildMember. The channel is placed under the Temporary Voice Channels category and the creating member is given permissions to manage it. The user is then moved to this new channel.
member: TheGuildMemberobject for whom the channel is to be created.
deleteTemporaryChannel(channel) (Private Method)
Deletes a specified temporary voice channel. This method is typically called when the channel becomes empty.
channel: TheVoiceChannelobject to be deleted.
isTemporaryChannel(guildId, channelId) (Private Method)
Checks if a given channel ID within a guild is a temporary channel managed by this instance.
guildId: The ID of the guild.channelId: The ID of the channel to check.
Important Notes
- Ensure your bot has the necessary permissions (
Manage Channels,Move Members,View Channel,Connect) in the category where temporary channels will be created. - The category name
Temporary Voice Channelsis hardcoded in thecreateTemporaryChannelmethod. If you use a different category name, you must update the code accordingly. - This package relies on
voiceStateUpdateevents, so ensure yourdiscord.jsclient hasGatewayIntentBits.GuildVoiceStatesenabled.
