Native voice plugin for discordjs-nextgen.
npm install discordjs-nextgen discordjs-nextgen-voiceimport { 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.
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.');
},
};await app.voice.join({
guildId: 'GUILD_ID',
channelId: 'VOICE_CHANNEL_ID',
});app.use(new VoicePlugin({
adapterProvider: (guildId, ctx) => {
return undefined;
},
}));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.');
},
};ctx.voice.pause();
ctx.voice.resume();
ctx.voice.skip();
ctx.voice.stop();
ctx.voice.leave();const daveStateCommand = {
name: 'davestate',
run: async (ctx) => {
const state = ctx.voice.getDaveState();
await ctx.reply(`DAVE phase: ${state.phase}, requiredByServer: ${state.requiredByServer}`);
},
};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()
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.
MIT