Submodules¶
Package Contents¶
Classes¶
A usefull class to track invites of member whenever a user is invited to a guild. |
|
The requested song data |
|
The class which acts a music controller/player |
|
The manager class to initiate and music and manage its player |
|
Embed which has whoose colors are randomly generated |
|
The Embed used to depict an |
|
The Embed used to depict any kind of success |
|
The Embed used to depict any kind of warning or starboard kind of |
|
Represents a UI view. |
|
A page source that requires (field_name, field_value) tuple items. |
|
A data source for a sequence of items. |
|
A data source for a sequence of items. |
|
A simple pagination session reminiscent of the old Pages interface. |
|
A data source for a sequence of items. |
|
A simple paginator for the embeds. In entries you provides a list of embeds |
Functions¶
|
Formats the search string for the YouTube music search |
|
It returns required video data after searching YouTube |
|
It checks the music queue |
Attributes¶
- class DiscordUtils.InviteTracker(bot)[source]¶
A usefull class to track invites of member whenever a user is invited to a guild.
- Parameters
bot (Union[Client, AutoShardedClient, Bot, AutoSharededBot]) –
- Attributes
bot: The default bot class.
- _cache:
dict
A dict to cache
Guild
instancesInvite
- _cache:
- __slots__ = ['bot', '_cache']¶
- add_listeners(self)[source]¶
It adds the following listeners to the
Bot
instance.- Mapping
Function
Discord Function
on_ready()
on_invite_create()
on_invite_delete()
on_guild_join()
on_guild_remove()
- Return type
- await cache_invites(self)[source]¶
It cache the guild invites automatically whenever the
on_ready()
event is fired- Return type
- await update_invite_cache(self, invite)[source]¶
It updates the invite cache automatically whenever the
on_invite_create()
event is fired- Parameters
invite (discord.Invite) –
- Return type
- await remove_invite_cache(self, invite)[source]¶
It removes the invite cache of the deleted invite automatically whenever the
on_invite_delete()
event is fired- Parameters
invite (discord.Invite) –
- await add_guild_cache(self, guild)[source]¶
It adds the guild to cache automatically whenever the
on_guild_join()
event is fired- Parameters
guild (discord.Guild) –
- Return type
- await remove_guild_cache(self, guild)[source]¶
It removes the guild from cache automatically whenever the
on_guild_remove()
event is fired- Parameters
guild (discord.Guild) –
- Return type
- await fetch_inviter(self, member)[source]¶
This utility function returns the
Invite
class which was used when the member joined the guild.- Parameters
member (discord.Member) – The member which joined the guild. (The
Member
recieved duringon_member_join()
event)- Returns
If the member was bot i.e. invited via integration then it would return
None
- Return type
Optional[discord.Invite]
- DiscordUtils.has_voice = True¶
- DiscordUtils.bug_reports_message¶
- exception DiscordUtils.NotConnectedToVoice[source]¶
Bases:
Exception
Cannot create the player because bot is not connected to voice
- exception DiscordUtils.NotPlaying[source]¶
Bases:
Exception
Cannot <do something> because nothing is being played
- await DiscordUtils.ytbettersearch(query)[source]¶
Formats the search string for the YouTube music search
- Return type
- class DiscordUtils.Song(source, url, title, description, views, duration, thumbnail, channel, channel_url, loop)[source]¶
The requested song data
- Parameters
- __slots__ = ['source', 'url', 'title', 'description', 'views', 'duration', 'thumbnail', 'channel',...¶
- await DiscordUtils.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
- Parameters
search (bool) –
bettersearch (bool) –
loop (Optional[asyncio.AbstractEventLoop]) –
- DiscordUtils.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 afterwardson_play (MusicPlayer.on_play) –
MusicPlayer.on_play()
functionloop (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
- class DiscordUtils.MusicPlayer(ctx, music, **kwargs)[source]¶
The class which acts a music controller/player
- Raises
RuntimeError – Is raised when the package is install without the .[voice] parameters
NotPlaying – See
skip()
,stop()
,resume()
,pause()
,toggle_song_loop()
,change_volume()
,remove_from_queue()
EmptyQueue – See
skip()
,current_queue()
- Parameters
ctx (discord.ext.commands.Context) –
music (Music) –
- __slots__ = ['ctx', 'voice', 'loop', 'music', 'after_func', 'on_play_func', 'on_queue_func', 'on_skip_func',...¶
- on_queue(self, func)[source]¶
The event when the song is queued
- Parameters
func (Callable) –
- Return type
- on_play(self, func)[source]¶
The event when the song is played
- Parameters
func (Callable) –
- Return type
- on_skip(self, func)[source]¶
The event when the song is skipped
- Parameters
func (Callable) –
- Return type
- on_stop(self, func)[source]¶
The event when the player is stopped
- Parameters
func (Callable) –
- Return type
- on_pause(self, func)[source]¶
The event when the song is paused
- Parameters
func (Callable) –
- Return type
- on_resume(self, func)[source]¶
The event when the song is resumed
- Parameters
func (Callable) –
- Return type
- on_loop_toggle(self, func)[source]¶
The event when the looping is enabled
- Parameters
func (Callable) –
- Return type
- on_volume_change(self, func)[source]¶
The event when the volume is changed
- Parameters
func (Callable) –
- Return type
- on_remove_from_queue(self, func)[source]¶
The event when the song is removed from the queue
- Parameters
func (Callable) –
- Return type
- await play(self)[source]¶
Determines which song to play from the queue
- Returns
See above
- Return type
- 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
- await stop(self)[source]¶
Stops the player
- Raises
NotPlaying – When nothing is played
- Return type
- await pause(self)[source]¶
Pauses the player
- Raises
NotPlaying – When nothing is played
- Returns
The song on which the pause was initiated
- Return type
- 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
- 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
- await remove_from_queue(self, index)[source]¶
The utility function to remove
Song
from the queue- Parameters
- Raises
NotPlaying – When nothing is player by the player
- Returns
The song to be removed from the player
- Return type
- class DiscordUtils.Music[source]¶
The manager class to initiate and music and manage its player
- Raises
RuntimeError – Is raised when the package is install without the .[voice] parameters
- __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
- get_player(self, **kwargs)[source]¶
Its gets the MusicPlayer of the specified guild or voice channel
- Returns
See above
- Return type
Optional[MusicPlayer]
- class DiscordUtils.Embed(**kwargs)[source]¶
Bases:
discord.embeds.Embed
Embed which has whoose colors are randomly generated The random color are generated using
discord.Color.random()
- class DiscordUtils.ErrorEmbed(**kwargs)[source]¶
Bases:
discord.embeds.Embed
The Embed used to depict an
Exception
The red color are generated usingdiscord.Color.red()
- class DiscordUtils.SuccessEmbed(**kwargs)[source]¶
Bases:
discord.embeds.Embed
The Embed used to depict any kind of success The green color are generated using
discord.Color.green()
- class DiscordUtils.StarboardEmbed(**kwargs)[source]¶
Bases:
discord.embeds.Embed
The Embed used to depict any kind of warning or starboard kind of
Embed
The green color are generated usingdiscord.Color.green()
- class DiscordUtils.RoboPages(source, *, ctx, check_embeds=True, compact=False)[source]¶
Bases:
discord.ui.View
Represents a UI view.
This object must be inherited to create a UI within Discord.
New in version 2.0.
- Parameters
- await interaction_check(self, interaction)[source]¶
This function is a coroutine.
A callback that is called when an interaction happens within the view that checks whether the view should process item callbacks for the interaction.
This is useful to override if, for example, you want to ensure that the interaction author is a given user.
The default implementation of this returns
True
.Note
If an exception occurs within the body then the check is considered a failure and
on_error()
is called.- Parameters
interaction (
Interaction
) – The interaction that occurred.- Returns
Whether the view children’s callbacks should be called.
- Return type
- await on_timeout(self)[source]¶
This function is a coroutine.
A callback that is called when a view’s timeout elapses without being explicitly stopped.
- Return type
- staticmethod await on_error(error, item, interaction)[source]¶
This function is a coroutine.
A callback that is called when an item’s callback or
interaction_check()
fails with an error.The default implementation logs to the library logger.
- await go_to_first_page(self, button, interaction)[source]¶
Go to the first page
- Parameters
button (discord.ui.Button) –
interaction (discord.Interaction) –
- await go_to_previous_page(self, button, interaction)[source]¶
Go to the previous page
- Parameters
button (discord.ui.Button) –
interaction (discord.Interaction) –
- await go_to_current_page(self, button, interaction)[source]¶
As the name suggests, goes to the current page
- Parameters
button (discord.ui.Button) –
interaction (discord.Interaction) –
- await go_to_next_page(self, button, interaction)[source]¶
Go to the next page
- Parameters
button (discord.ui.Button) –
interaction (discord.Interaction) –
- await go_to_last_page(self, button, interaction)[source]¶
Go to the last page
- Parameters
button (discord.ui.Button) –
interaction (discord.Interaction) –
- class DiscordUtils.FieldPageSource(entries, *, per_page=12)[source]¶
Bases:
discord.ext.menus.ListPageSource
A page source that requires (field_name, field_value) tuple items.
- await format_page(self, menu, entries)[source]¶
This function could be a coroutine.
An abstract method to format the page.
This method must return one of the following types.
If this method returns a
str
then it is interpreted as returning thecontent
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
discord.Embed
then it is interpreted as returning theembed
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
dict
then it is interpreted as the keyword-arguments that are used in bothdiscord.Message.edit()
anddiscord.abc.Messageable.send()
. The two of interest areembed
andcontent
.
- class DiscordUtils.TextPageSource(text, *, prefix='```', suffix='```', max_size=2000)[source]¶
Bases:
discord.ext.menus.ListPageSource
A data source for a sequence of items.
This page source does not handle any sort of formatting, leaving it up to the user. To do so, implement the
format_page()
method.- entries¶
The sequence of items to paginate.
- Type
Sequence[Any]
- await format_page(self, menu, content)[source]¶
This function could be a coroutine.
An abstract method to format the page.
This method must return one of the following types.
If this method returns a
str
then it is interpreted as returning thecontent
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
discord.Embed
then it is interpreted as returning theembed
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
dict
then it is interpreted as the keyword-arguments that are used in bothdiscord.Message.edit()
anddiscord.abc.Messageable.send()
. The two of interest areembed
andcontent
.
- class DiscordUtils.SimplePageSource(entries, *, per_page)[source]¶
Bases:
discord.ext.menus.ListPageSource
A data source for a sequence of items.
This page source does not handle any sort of formatting, leaving it up to the user. To do so, implement the
format_page()
method.- entries¶
The sequence of items to paginate.
- Type
Sequence[Any]
- await format_page(self, menu, entries)[source]¶
This function could be a coroutine.
An abstract method to format the page.
This method must return one of the following types.
If this method returns a
str
then it is interpreted as returning thecontent
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
discord.Embed
then it is interpreted as returning theembed
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
dict
then it is interpreted as the keyword-arguments that are used in bothdiscord.Message.edit()
anddiscord.abc.Messageable.send()
. The two of interest areembed
andcontent
.
- class DiscordUtils.SimplePages(entries, *, ctx, per_page=12)[source]¶
Bases:
RoboPages
A simple pagination session reminiscent of the old Pages interface. Basically an embed with some normal formatting.
- Parameters
ctx (discord.ext.commands.Context) –
per_page (int) –
- class DiscordUtils.EmbedPageSource(entries, *, per_page)[source]¶
Bases:
discord.ext.menus.ListPageSource
A data source for a sequence of items.
This page source does not handle any sort of formatting, leaving it up to the user. To do so, implement the
format_page()
method.- entries¶
The sequence of items to paginate.
- Type
Sequence[Any]
- staticmethod await format_page(menu, entries)[source]¶
This function could be a coroutine.
An abstract method to format the page.
This method must return one of the following types.
If this method returns a
str
then it is interpreted as returning thecontent
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
discord.Embed
then it is interpreted as returning theembed
keyword argument indiscord.Message.edit()
anddiscord.abc.Messageable.send()
.If this method returns a
dict
then it is interpreted as the keyword-arguments that are used in bothdiscord.Message.edit()
anddiscord.abc.Messageable.send()
. The two of interest areembed
andcontent
.
- class DiscordUtils.EmbedPaginator(entries, *, ctx)[source]¶
Bases:
RoboPages
A simple paginator for the embeds. In entries you provides a list of embeds
- Parameters
ctx (discord.ext.commands.Context) –
- DiscordUtils.__title__ = DiscordUtils¶
- DiscordUtils.__version__ = 1.3.5¶
- DiscordUtils.__author__ = Dhruvacube¶
- DiscordUtils.__license__ = MIT¶