mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
chore: monorepo setup (#7175)
This commit is contained in:
66
packages/voice/src/joinVoiceChannel.ts
Normal file
66
packages/voice/src/joinVoiceChannel.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { createVoiceConnection } from './VoiceConnection';
|
||||
import type { JoinConfig } from './DataStore';
|
||||
import type { DiscordGatewayAdapterCreator } from './util/adapter';
|
||||
|
||||
/**
|
||||
* The options that can be given when creating a voice connection.
|
||||
*/
|
||||
export interface CreateVoiceConnectionOptions {
|
||||
/**
|
||||
* If true, debug messages will be enabled for the voice connection and its
|
||||
* related components. Defaults to false.
|
||||
*/
|
||||
debug?: boolean;
|
||||
|
||||
adapterCreator: DiscordGatewayAdapterCreator;
|
||||
}
|
||||
|
||||
/**
|
||||
* The options that can be given when joining a voice channel.
|
||||
*/
|
||||
export interface JoinVoiceChannelOptions {
|
||||
/**
|
||||
* The id of the Discord voice channel to join.
|
||||
*/
|
||||
channelId: string;
|
||||
|
||||
/**
|
||||
* The id of the guild that the voice channel belongs to.
|
||||
*/
|
||||
guildId: string;
|
||||
|
||||
/**
|
||||
* Whether to join the channel deafened (defaults to true)
|
||||
*/
|
||||
selfDeaf?: boolean;
|
||||
|
||||
/**
|
||||
* Whether to join the channel muted (defaults to true)
|
||||
*/
|
||||
selfMute?: boolean;
|
||||
|
||||
/**
|
||||
* An optional group identifier for the voice connection.
|
||||
*/
|
||||
group?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a VoiceConnection to a Discord voice channel.
|
||||
*
|
||||
* @param voiceChannel - the voice channel to connect to
|
||||
* @param options - the options for joining the voice channel
|
||||
*/
|
||||
export function joinVoiceChannel(options: JoinVoiceChannelOptions & CreateVoiceConnectionOptions) {
|
||||
const joinConfig: JoinConfig = {
|
||||
selfDeaf: true,
|
||||
selfMute: false,
|
||||
group: 'default',
|
||||
...options,
|
||||
};
|
||||
|
||||
return createVoiceConnection(joinConfig, {
|
||||
adapterCreator: options.adapterCreator,
|
||||
debug: options.debug,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user