discordaudio
TypeScript icon, indicating that this package has built-in type declarations

3.1.19 • Public • Published

Discord Audio

downloadsBadge versionBadge documentationBadge

🔧 Installation

Install Discord Audio

$ npm install discordaudio@latest
$ yarn add discordaudio@latest

ℹ️ About

Discord Audio is a stable and easy to use discord voice channel framework which is compatible with multiple Discord.js versions. Discord Audio makes you able to play your favorite songs in a voice channel with your Discord bot.

🔑 Features

  • AudioManager - Create a music bot if you are a developer with not many experience
  • Player - Create a music bot if you are a developer with experience
  • Connection - Create a bot that plays a stream that never ends
  • Broadcast - Create a broadcast to play in multiple servers
  • Adapter - Create an adapter to play a song in a voice channel if you are not using Discord Audio

🔗 Links

📖 Example

const { AudioManager } = require('discordaudio');
const discord = require('discord.js');

const client = new discord.Client({intents: [discord.GatewayIntentBits.FLAGS.GUILDS, discord.GatewayIntentBits.FLAGS.GUILD_MESSAGES, discord.GatewayIntentBits.FLAGS.GUILD_VOICE_STATES]});

const config = {
    token: 'Your-Secret-Token',
    prefix: '-'
};

const connections = new Map();

const audioManager = new AudioManager();

client.once('ready', () => console.log(`${client.user.username} is online!`));

client.on('messageCreate', message => {
    if(message.author.bot || message.channel.type === `DM`) return;
    
    if(!message.content.startsWith(config.prefix)) return;
    
    let args = message.content.substring(config.prefix.length).split(" ");
    
    const vc = connections.get(message.guild,members.me.voice.channel?.id);
    
    switch(args[0].toLowerCase()){
        case 'play':
            if(!message.member.voice.channel && !message.guild.members.me.voice.channel) return message.channel.send({content: `Please join a voice channel in order to play a song!`});
            if(!args[1]) return message.channel.send({content: `Please provide a song`});
            const uvc = message.member.voice.channel || message.guild.members.me.voice.channel;
            audioManager.play(uvc, args[1], {
                quality: 'high',
                audiotype: 'arbitrary',
                volume: 10
            }).then(queue => {
                connections.set(uvc.id, uvc);
                if(queue === false) message.channel.send({content: `Your song is now playing!`});
                else message.channel.send({content: `Your song has been added to the queue!`});
            }).catch(err => {
                console.log(err);
                message.channel.send({content: `There was an error while trying to connect to the voice channel!`});
            });
            break;
        case 'skip':
            if(!vc) return message.channel.send({content: `There is currently nothing playing!`});
            audioManager.skip(vc).then(() => message.channel.send({content: `Successfully skipped the song!`})).catch(err => {
                console.log(err);
                message.channel.send({content: `There was an error while skipping the song!`});
            });
            break;
        case 'stop':
            if(!vc) return message.channel.send({content: `There is currently nothing playing!`});
            audioManager.stop(vc);
            message.channel.send({content: `Player successfully stopped!`});            
            break;
        case 'queue':
            if(!vc) return message.channel.send({content: `There is currently nothing playing!`});
            const queue = audioManager.queue(vc).reduce((text, song, index) => {
                if(index > 50){
                    return text;
                } else if(index > 49){
                    text += `\n...`;
                    return text;
                }
                if(song.title) text += `\n**[${index + 1}]** ${song.title}`;
                else text += `\n**[${index + 1}]** ${song.url}`;
                return text;
            }, `__**QUEUE**__`);
            const queueEmbed = new discord.EmbedBuilder()
            .setColor(`Blurple`)
            .setTitle(`Queue`)
            .setDescription(queue);
            message.channel.send({embeds: [queueEmbed]});
            break;
        case 'volume':
            if(!vc) return message.channel.send({content: `There is currently nothing playing!`});
            if(!args[1]) return message.channel.send({content: `Please provide the volume`});
            if(Number(args[1]) < 1 || Number(args[1]) > 10) return message.channel.send({content: `Please provide a volume between 1-10`});
            audioManager.volume(vc, Number(args[1]));
            break;
        case 'shuffle':
            if(!vc) return message.channel.send({content: `There is currently nothing playing!`});
            audioManager.shuffle(vc);
            message.channel.send({content: `The queue has successfully been shufffled`});
            break;
    }
});

client.login(config.token);

Do you have an issue or a question? Go to the issue page or send me a DM on Discord (luukw)

Package Sidebar

Install

npm i discordaudio

Weekly Downloads

206

Version

3.1.19

License

MIT

Unpacked Size

139 kB

Total Files

19

Last publish

Collaborators

  • luuk-dev