Giter Site home page Giter Site logo

discordutils's Introduction

This package is not maintained anymore

DiscordUtils

A very useful library made to be used in with discord.py

Installation

For access to Pagination and InviteTracker use:

pip install DiscordUtils

or, instead use the following for access to Music functions aswell

pip install DiscordUtils[voice]

Requires discord.py[voice] so make sure you have all dependencies of it installed.

Example code

DiscordUtils.Pagination.AutoEmbedPaginator

@bot.command()
async def paginate(ctx):
    embed1 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 1")
    embed2 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 2")
    embed3 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 3")
    paginator = DiscordUtils.Pagination.AutoEmbedPaginator(ctx)
    embeds = [embed1, embed2, embed3]
    await paginator.run(embeds)

DiscordUtils.Pagination.CustomEmbedPaginator

@bot.command()
async def paginate(ctx):
    embed1 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 1")
    embed2 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 2")
    embed3 = discord.Embed(color=ctx.author.color).add_field(name="Example", value="Page 3")
    paginator = DiscordUtils.Pagination.CustomEmbedPaginator(ctx)
    paginator.add_reaction('⏮️', "first")
    paginator.add_reaction('⏪', "back")
    paginator.add_reaction('🔐', "lock")
    paginator.add_reaction('⏩', "next")
    paginator.add_reaction('⏭️', "last")
    embeds = [embed1, embed2, embed3]
    await paginator.run(embeds)

DiscordUtils.InviteTracker

import discord
from discord.ext import commands
import DiscordUtils

intents = discord.intents.default()
intents.members = True
bot = commands.AutoShardedBot(command_prefix=">", intents=intents)
tracker = DiscordUtils.InviteTracker(bot)

@bot.event
async def on_member_join(member):
    inviter = await tracker.fetch_inviter(member) # inviter is the member who invited

DiscordUtils.Music

import discord
from discord.ext import commands
import DiscordUtils

bot = commands.AutoShardedBot(command_prefix=">")
music = DiscordUtils.Music()

@bot.command()
async def join(ctx):
    await ctx.author.voice.channel.connect() #Joins author's voice channel
    
@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()
    
@bot.command()
async def play(ctx, *, url):
    player = music.get_player(guild_id=ctx.guild.id)
    if not player:
        player = music.create_player(ctx, ffmpeg_error_betterfix=True)
    if not ctx.voice_client.is_playing():
        await player.queue(url, search=True)
        song = await player.play()
        await ctx.send(f"Playing {song.name}")
    else:
        song = await player.queue(url, search=True)
        await ctx.send(f"Queued {song.name}")
        
@bot.command()
async def pause(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    song = await player.pause()
    await ctx.send(f"Paused {song.name}")
    
@bot.command()
async def resume(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    song = await player.resume()
    await ctx.send(f"Resumed {song.name}")
    
@bot.command()
async def stop(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    await player.stop()
    await ctx.send("Stopped")
    
@bot.command()
async def loop(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    song = await player.toggle_song_loop()
    if song.is_looping:
        await ctx.send(f"Enabled loop for {song.name}")
    else:
        await ctx.send(f"Disabled loop for {song.name}")
    
@bot.command()
async def queue(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    await ctx.send(f"{', '.join([song.name for song in player.current_queue()])}")
    
@bot.command()
async def np(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    song = player.now_playing()
    await ctx.send(song.name)
    
@bot.command()
async def skip(ctx):
    player = music.get_player(guild_id=ctx.guild.id)
    data = await player.skip(force=True)
    if len(data) == 2:
        await ctx.send(f"Skipped from {data[0].name} to {data[1].name}")
    else:
        await ctx.send(f"Skipped {data[0].name}")

@bot.command()
async def volume(ctx, vol):
    player = music.get_player(guild_id=ctx.guild.id)
    song, volume = await player.change_volume(float(vol) / 100) # volume should be a float between 0 to 1
    await ctx.send(f"Changed volume for {song.name} to {volume*100}%")
    
@bot.command()
async def remove(ctx, index):
    player = music.get_player(guild_id=ctx.guild.id)
    song = await player.remove_from_queue(int(index))
    await ctx.send(f"Removed {song.name} from queue")

For further information please read the docs

Links

Documentation

Github

Support

Please make sure that you are on the latest version of DiscordUtils and youtube_dl before contacting for support

DM/PM toxic_recker#2795 on Discord for support

discordutils's People

Contributors

actualdankcoder avatar d3crypt360 avatar jaydwee avatar kabir-sidhu avatar shinyzenith avatar taromaruyuki avatar toxicrecker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

discordutils's Issues

Unnecessary heavy dependencies should not be compulsory

The title says it all; youtube_dl and discord.py[voice] are not dependencies that everyone needs. They should not be compulsory installs with this, when someone just wants to use, say the paginator or the invite tracker.

They should be made into optional installs, that users could choose to install.

Examples do not work

Hi there, I installed the latest version of discordUtils==1.28, discord.py==1.7.0 and python 3.8
I tried the examples and they do not print anything. also I do not get any errors in my console.

skip tracks but don't remove from the queue

It would be really nice to have an option to skip a track and don't loose it, i guess it could make it easier to loop queues in the future
something like skip(delete=False)

Add note that member intents required for pagination

Just a quick suggestion that may be beneficial to include somewhere in the documentation or examples, that pagination requires the bot to have privileged intents enabled. I spent an hour struggling to identify the issue when pagination works in one of my bots but not the other; my fault since I'm well-aware of what privileged intents are, but it may also be useful for more less experienced developers who have little to no experience with it.

Can't go to docs

I cant go to docs, and also cant go to github page via the link of pypi page

Invite Tracker - KeyError: guild.id

When A user joines the guild and the on_member_join event runs, whenever it gets to inviter = await tracker.fetch_inviter(member) then it says Keyerror: {guild.id}

Is there something I should do or is it a problem with DiscordUtils?

[Suggestion] Allow pagination using multiple kinds of interactions

Comparing different alternatives for pagination. I saw a lower level implementation using discord components, using buttons to navigate pages (see this implementation).

I love the facilities that the Paginators here use, but using discord components would greatly enhance the user experience. As for implementation goes I would suggest to generalize the different reactions, buttons and other interactions (perhaps even commands) as "InteractionControllers" or a similar concept. And base the paginator on those controller interfaces instead of message reactions only.

Sounds like an interesting problem to tackle myself, tbh. But rn I'm more interested in adding features to my bots. So let me know if anyone else is interested.

Also allowing the developer to add before_interaction and after_interaction calls would also allow for even more use cases for this utility. For doing API calls per page for example.

Skip function in DiscordUtils.Music()

Everything works as is but the data that is being sent to me by the skip command, namely the old and new song name, displays the same name. I'm using the sample code for async def skip on DiscordUtils.Music()

image
image

Player object error

After reading the docs, trying on my own, and constantly getting errors I decided I would try your code but it gave the same error. Whenever I use the player it says TypeError: 'NoneType' object is not subscriptable or when I use the volume command it says 'NoneType' object has no attribute 'change_volume'. I'm using python 3.8 because I had an error installing with 3.9

play not working from example code

When using the default music code in Readme I get 2 exceptions when using play(). Upates to both youtube and discord.py seem to be the issues for this.

1)

\DiscordUtils\Music.py", line 196, in play
source = discord.PCMVolumeTransformer(discord.FFmpegPCMAudio(self.music.queue[self.ctx.guild.id][0].source, **self.ffmpeg_opts))

A symptom of an exception from discord.py but it's broken the play function in Music.py.

2) Dislike Count

site-packages\DiscordUtils\Music.py", line 92, in get_video_data
dislikes = data["dislike_count"]
KeyError: 'dislike_count'

Stupid youtube updates.

Code Example Play doesn't work

When i try to run the play command from the code example of the music system, i get following errors

with a seach query
ERROR: query "crab rave": Failed to parse JSON (caused by JSONDecodeError('Expecting value: line 1 column 1 (char 0)')) Ignoring exception in command play: Traceback (most recent call last): File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "c:\Users\admin\Desktop\Python Code\test.py", line 22, in play await player.queue(url, search=True) File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\DiscordUtils\Music.py", line 171, in queue song = await get_video_data(url, search, bettersearch, self.loop) File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\DiscordUtils\Music.py", line 70, in get_video_data data = data["entries"][0] TypeError: 'NoneType' object is not subscriptable

with a direct video link
ERROR: No video formats found Ignoring exception in command play: Traceback (most recent call last): File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped ret = await coro(*args, **kwargs) File "c:\Users\admin\Desktop\Python Code\test.py", line 22, in play await player.queue(url, search=True) File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\DiscordUtils\Music.py", line 171, in queue song = await get_video_data(url, search, bettersearch, self.loop) File "C:\Users\admin\AppData\Local\Programs\Python\Python38-32\lib\site-packages\DiscordUtils\Music.py", line 70, in get_video_data data = data["entries"][0] TypeError: 'NoneType' object is not subscriptable

Bot leaving and not playing after rejoining

When the bot leaves and rejoins i get an error when i whant him to play a song: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Not connected to voice.

Using a local image within a paginated embed

This isn't an "issue" but I'm trying to use a local image within a paginated embed and am striking out. I can embed an image within a non-paginated embed just fine using the following:

file = discord.File("imagename.png", filename="image.png")
embed = discord.Embed(title="foo")
embed.set_image(url="attachment://image.png")
await ctx.send(file=file, embed=embed)

But when attempting to utilize similar syntax with the paginator, it seems to not enjoy having another variable to process.

An example:

ctx.bot.loop.create_task(paginator.run(file=file, embeds=embeds))

I've tried a couple variations, but to no avail. The best I can get is either the embeds without the image or the image as an attachment (as a normal message, outside of an embed).

If anyone has any suggestions, I'm all ears

Bot not playing any song.

I have the exact same code as written in the docs. Whenever I use the play command, it throws me the following error:

Unrecognized option 'reconnect'.
Error splitting the argument list: Option not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.