DiscordUtils.music


Module Contents

Classes

Song

The requested song data

MusicPlayer

The class which acts a music controller/player

Music

The manager class to initiate and music and manage its player

Functions

ytbettersearch(query)

Formats the search string for the YouTube music search

get_video_data(url, search, bettersearch, loop)

It returns required video data after searching YouTube

check_queue(ctx, opts, music, after, on_play, loop)

It checks the music queue

Attributes

DiscordUtils.music.has_voice = True
DiscordUtils.music.bug_reports_message
exception DiscordUtils.music.EmptyQueue[source]

Bases: Exception

Cannot skip because queue is empty

exception DiscordUtils.music.NotConnectedToVoice[source]

Bases: Exception

Cannot create the player because bot is not connected to voice

exception DiscordUtils.music.NotPlaying[source]

Bases: Exception

Cannot <do something> because nothing is being played

await DiscordUtils.music.ytbettersearch(query)[source]

Formats the search string for the YouTube music search

Return type

str

class DiscordUtils.music.Song(source, url, title, description, views, duration, thumbnail, channel, channel_url, loop)[source]

The requested song data

Parameters
  • source (str) –

  • url (str) –

  • title (str) –

  • description (str) –

  • views (int) –

  • duration (Union[str, int]) –

  • thumbnail (str) –

  • channel (str) –

  • channel_url (str) –

  • loop (bool) –

__slots__ = ['source', 'url', 'title', 'description', 'views', 'duration', 'thumbnail', 'channel',...
await DiscordUtils.music.get_video_data(url, search, bettersearch, loop)[source]

It returns required video data after searching YouTube

Raises

RuntimeError – Is raised when the package is install without the .[voice] parameters

Returns

The song data in a formatted way

Return type

Song

Parameters
  • search (bool) –

  • bettersearch (bool) –

  • loop (Optional[asyncio.events.AbstractEventLoop]) –

DiscordUtils.music.check_queue(ctx, opts, music, after, on_play, loop)[source]

It checks the music queue

Parameters
  • ctx (commands.Context) – The commands context

  • opts (dict) – A set options for ffmpeg

  • music (Music) – The master class where the all the players data is stored

  • after (Callable) – The check_queue() which would be called afterwards

  • on_play (MusicPlayer.on_play) – MusicPlayer.on_play() function

  • loop (Optional[asyncio.AbstractEventLoop]) – The event loop in which the Bot is running

Raises

RuntimeError – Is raised when the package is install without the .[voice] parameters

Return type

None

class DiscordUtils.music.MusicPlayer(ctx, music, **kwargs)[source]

The class which acts a music controller/player

Raises
Parameters
  • ctx (discord.ext.commands.context.Context) –

  • music (Music) –

__slots__ = ['ctx', 'voice', 'loop', 'music', 'after_func', 'on_play_func', 'on_queue_func', 'on_skip_func',...
disable(self)[source]

It disables the Music Player

on_queue(self, func)[source]

The event when the song is queued

Parameters

func (Callable) –

Return type

None

on_play(self, func)[source]

The event when the song is played

Parameters

func (Callable) –

Return type

None

on_skip(self, func)[source]

The event when the song is skipped

Parameters

func (Callable) –

Return type

None

on_stop(self, func)[source]

The event when the player is stopped

Parameters

func (Callable) –

Return type

None

on_pause(self, func)[source]

The event when the song is paused

Parameters

func (Callable) –

Return type

None

on_resume(self, func)[source]

The event when the song is resumed

Parameters

func (Callable) –

Return type

None

on_loop_toggle(self, func)[source]

The event when the looping is enabled

Parameters

func (Callable) –

Return type

None

on_volume_change(self, func)[source]

The event when the volume is changed

Parameters

func (Callable) –

Return type

None

on_remove_from_queue(self, func)[source]

The event when the song is removed from the queue

Parameters

func (Callable) –

Return type

None

await queue(self, url, search=False, bettersearch=False)[source]

The song to queue

Parameters
  • url (str) – The url of the song provider

  • search (bool, optional) – Song Name, defaults to False

  • bettersearch (bool, optional) – Search betterly or not, defaults to False

Returns

The song with the minimum required data

Return type

Song

await play(self)[source]

Determines which song to play from the queue

Returns

See above

Return type

Song

await skip(self, force=False)[source]

Skips the current song which is being played

Parameters

force (bool, optional) – Force skip or not, defaults to False

Raises
  • NotPlaying – When there is no song played then this error is raised

  • EmptyQueue – When the queue is empty

Returns

It returns (old song, new song) or just (song) depending on the situtation

Return type

Union[Tuple[Song, Song], Song]

await stop(self)[source]

Stops the player

Raises

NotPlaying – When nothing is played

Return type

None

await pause(self)[source]

Pauses the player

Raises

NotPlaying – When nothing is played

Returns

The song on which the pause was initiated

Return type

Song

await resume(self)[source]

Resumes the player

Raises

NotPlaying – When nothing was played by the player previously

Returns

The song which will be played

Return type

Song

current_queue(self)[source]

Gives the current queue of songs which is there in the player

Raises

EmptyQueue – When the song queue is empty

Returns

_description_

Return type

Union[Iterable, Song]

now_playing(self)[source]

Returns the Song which is currently being played

Returns

See above

Return type

Optional[Union[Iterable, Song]]

await toggle_song_loop(self)[source]

It toggles on/off the looping

Raises

NotPlaying – When no song is being played

Returns

The currently playing song or the looped queue

Return type

Optional[Union[Iterable, Song]]

await change_volume(self, vol)[source]

Change the song volume of the currently played song

Parameters

vol (int) – The amount by the volume needs to increased or decreased

Raises

NotPlaying – When no song is played

Returns

(The song which is being played, volume no by which the song’s volume was increased or decreased)

Return type

Tuple[Song, int]

await remove_from_queue(self, index)[source]

The utility function to remove Song from the queue

Parameters

index (int) – The index at which the Song is located

Raises

NotPlaying – When nothing is player by the player

Returns

The song to be removed from the player

Return type

Song

delete(self)[source]

Removes the song from the queue

Return type

None

class DiscordUtils.music.Music[source]

The manager class to initiate and music and manage its player

Raises
__slots__ = ['queue', 'players']
create_player(self, ctx, **kwargs)[source]

It create a music player, using which the music will be played in the voice channels

Parameters

ctx (commands.Context) – The commands context

Raises

NotConnectedToVoice – When the client is not connect to any of the voice channel

Returns

The music player using the user will have the control over its requested songs

Return type

MusicPlayer

get_player(self, **kwargs)[source]

Its gets the MusicPlayer of the specified guild or voice channel

Returns

See above

Return type

Optional[MusicPlayer]