discordjs-nextgen-voice
v0.2.0
Published
Native voice plugin for discordjs-nextgen (without @discordjs/voice)
Downloads
1,246
Maintainers
Readme
discordjs-nextgen-voice
Native voice plugin for discordjs-nextgen.
Installation
npm install discordjs-nextgen discordjs-nextgen-voiceQuick Usage
import { App, Intents } from 'discordjs-nextgen';
import { VoicePlugin } from 'discordjs-nextgen-voice';
const app = new App({ intents: Intents.ALL });
app.use(new VoicePlugin({
autoLeave: true,
defaultVolume: 0.5,
dave: {
enabled: true,
maxProtocolVersion: 1,
},
}));The plugin automatically uses the adapter provided by discordjs-nextgen core.
Join a Voice Channel
ctx.voice.join
const joinCommand = {
name: 'join',
run: async (ctx, args) => {
const channelId = args[0];
if (!channelId) {
return ctx.reply('Usage: !join <channelId>');
}
await ctx.voice.join({ channelId });
await ctx.reply('Joined the voice channel.');
},
};app.voice.join
await app.voice.join({
guildId: 'GUILD_ID',
channelId: 'VOICE_CHANNEL_ID',
});Optional Adapter Customization
app.use(new VoicePlugin({
adapterProvider: (guildId, ctx) => {
return undefined;
},
}));Play Audio
const playCommand = {
name: 'play',
run: async (ctx, args) => {
const url = args[0];
await ctx.voice.play(url, {
title: 'Requested song',
requestedBy: ctx.user.tag,
join: {
channelId: 'VOICE_CHANNEL_ID',
},
});
await ctx.reply('Playback started.');
},
};Other Commands
ctx.voice.pause();
ctx.voice.resume();
ctx.voice.skip();
ctx.voice.stop();
ctx.voice.leave();DAVE Debug
const daveStateCommand = {
name: 'davestate',
run: async (ctx) => {
const state = ctx.voice.getDaveState();
await ctx.reply(`DAVE phase: ${state.phase}, requiredByServer: ${state.requiredByServer}`);
},
};API
app.voice.join({ guildId, channelId, adapterCreator })app.voice.play(guildId, source, options?)app.voice.pause(guildId)app.voice.resume(guildId)app.voice.skip(guildId)app.voice.stop(guildId)app.voice.setVolume(guildId, value)app.voice.getQueue(guildId)ctx.voice.join(...)ctx.voice.play(...)ctx.voice.pause()ctx.voice.resume()ctx.voice.skip()ctx.voice.stop()ctx.voice.setVolume(value)ctx.voice.getQueue()
Notes
ffmpegis required for remote URLs or stream sources. The package ships withffmpeg-static.- Your bot needs
ConnectandSpeakpermissions. - For YouTube support, create a stream via a library like
play-dland pass it toctx.voice.play(stream). ctx.voice.join()andctx.voice.play(..., { join: ... })require a guild context.
License
MIT
