Skip to content

πŸ–ΌοΈ NodeJs library for discord to make 24/7 audio streaming easier.

License

Notifications You must be signed in to change notification settings

FrauJulian/Discord-Audio-Stream

Repository files navigation

Discord Audio Stream

npm GitHub package.json version GitHub Repo stars

This module is designed to work with discord.js/voice v0.19. This package doesn't support older versions!

Designed for 24/7 audio playing on discord.
Discord has many unwanted rate limits, especially in the audio area. This package does all the work and ensures that your music never stops playing due to ffmpeg or Discord, with as little effort as possible.

Recommended best Practise:
Create a global Map<GuildId, AudioManager> (Map<KEY, OBJ>) list. When the feature is used on a guild, add a new instance of AudioManager to the Map. When starting the connection or audio, overwrite the respective configuration with the override methods provided. To finally start, use the respective method. For each call and each change, retrieve the AudioManager object from the list and perform your actions. When the feature get stopped, first execute StopConnection and then Dispose to save as much power as possible. Garbage collection does the rest.
For large features: For large systems, it is recommended to queue each start with the packet p-queue, to give ffmpeg enough time..

πŸ‘‹ Support

Please create an issue on github or write fraujulian on discord!

πŸ“ Usage

Installation

Node.js 22.12.0 or newer is required.

npm install discord-audio-stream
yarn add discord-audio-stream
pnpm add discord-audio-stream
bun add discord-audio-stream

Required Dependencies

AudioManager Instance

Constructor

AudioManager(ffmpegMode: string, renewInMs, number, connectionData: VoiceConnectionDataModel, audioData: VoiceAudioDataModel): IDisposable, IAudioManager
  • ffmpegMode: 'Native' or 'Standalone'
  • renewInMs: renewal time, default 1,5h = 5400000ms - optional
  • connectionData: options for voice connection - optional
  • audioData: options for audio player - optional

Example

let audioManager = new AudioManager(
    'Native',
    5400000,
    {
        VoiceChannelId: 0, //voice channel id where to play music
        GuildId: 0, //guild id
        VoiceAdapter: 0, //guild VoiceAdapter
    },
    {
        ResourceType: '', //resource type like link or file
        Resource: '', //auto play link or file name
    },
);

Fields and Methods of AudioManager

Fields

Name Type Security Description
Active bool protected To check if the connection is active.
Playing bool protected To check if it is playing audio.

Methods

Name Parameters Return type Description
OverrideVoiceConnectionData connectionData: VoiceConnectionDataModel void To override intern connectionData field.
OverrideVoiceAudioDataModel audioData: VoiceAudioDataModel void To override intern audioData field.
CreateAndPlay Promise void Join channel and start playing audio.
CreateConnection void Let it connect to voice channel.
PlayAudio Promise void To start playing audio.
PauseAudio void Pause the audio, if it is playing
ResumeAudio void Resume the audio, if it is paused.
SetVolume volume: number (0 - 100 percent) void To set the audio volume.
StopConnection Promise void Method to disconnect the voice channel.
Dispose void Dispose all data in object.

πŸ“ Types

πŸ“‹ Contributors:

~ FrauJulian - Julian Lechner - CODEOWNER

🀝 Enjoy the package?

Give it a star ⭐ on github!

About

πŸ–ΌοΈ NodeJs library for discord to make 24/7 audio streaming easier.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

Contributors 3

  •  
  •  
  •