Skip to main content

A library to simplify discord.py

Project description

DPYS

The goal of DPYS is to make basic functionalities that every good bot needs easy to implement for beginners.

A big update was just released that added disnake support. If there are any bugs please report them here.

DPYS is a library that makes functionalites such as warnings, curse filter, reaction roles, anti mute evade, and many more easy to add to your bot. All DPYS databases use the aiosqlite library. Support for DPYS can be given in our Discord server. If you see any problems in the code or want to add a feature, create a pull request on our Github repository.


Install from pypi

python -m pip install dpys

Install from github

python -m pip install git+https://github.com/JGLTechnologies/dpys

Reaction role example


import dpys
from disnake.ext import commands
import disnake

bot = commands.AutoShardedBot(command_prefix="!")
TOKEN = "Your Token"


# Do not type hint disnake.Role for the role argument
# Command to create the reaction role
@commands.slash_command(name="rr")
async def reaction_role_command(inter: disnake.ApplicationCommandInteraction, emoji: str = commands.Param(
    description="An emoji or list of emojis"),
                                role: str = commands.Param(
                                    description="a Role or list of roles."),
                                title: str = commands.Param(description="The title for the embed"),
                                description: str = commands.Param(description="The description for the embed")):
    """
    It is used like this
    /rr emoji @role <Embed Title> <Embed Description>
    You can make one with multiple emojis and role.
    /rr emojis: emoji1, emoji2 roles: @role1, @role2 title Description
    Just make sure to separate the emojis and roles with commas and match the position of the roles and emojis.
    """
    await dpys.rr.command(
        inter, emoji, "Your dir goes here.", role, title, description
    )


# Adds role on reaction
@bot.listen("on_raw_reaction_add")
async def role_add(payload):
    await dpys.rr.add(payload, "Your dir goes here.", bot)


# Removes role when reaction is removed
@bot.listen("on_raw_reaction_remove")
async def role_remove(payload):
    await dpys.rr.remove(payload, "Your dir goes here.", bot)


# Command to list all current reaction roles in the guild
@commands.slash_command(name="listrr")
async def listrr(inter: disnake.ApplicationCommandInteraction):
    await dpys.rr.display(inter, "Your dir goes here.")


# Command to remove reaction role info from the database
@commands.slash_command(name="rrclear")
async def rrclear(inter: disnake.ApplicationCommandInteraction, id: str = commands.Param(
    description="The id or list of ids of the reaction roles you want to remove")):
    """
    Putting "all" as the id argument will wipe all reaction role data for the guild.
    To remove specific ones put the message id as the id argument. You can put multiple just separate by commas.
    The id can be found using the above command.
    This command does not need to be added if you use the event listeners bellow.
    """
    id = id.lower()
    if id == "all":
        await dpys.rr.clear_all(inter, "Your dir goes here.")
    else:
        await dpys.rr.clear_one(inter, "Your dir goes here.", int(id))


# Removes data for a reaction role when its message is deleted. Does not work with channel.purge(). For that you need dpys.rr.clear_on_raw_bulk_message_delete()
@bot.listen("on_message_delete")
async def rr_clear_on_message_delete(message):
    await dpys.rr.clear_on_message_delete(message, "Your dir goes here.")


# Removes data for a reaction role when its channel is deleted
@bot.listen("on_channel_delete")
async def rr_clear_on_channel_delete(channel):
    await dpys.rr.clear_on_channel_delete(channel, "Your dir goes here.")


# Removes data for a reaction role when its thread is deleted
@bot.listen("on_thread_delete")
async def rr_clear_on_thread_delete(thread):
    await dpys.rr.clear_on_thread_delete(thread, "Your dir goes here.")


# Removes data for a reaction role when its message is deleted in channel.purge()
@bot.listen("on_raw_bulk_message_delete")
async def rr_clear_on_raw_bulk_message_delete(payload):
    await dpys.rr.clear_on_raw_bulk_message_delete(payload, "Your dir goes here.")


# Clears all DPYS data for a guild when it is removed
@bot.listen("on_guild_remove")
async def clear_on_guild_remove(guild):
    await dpys.misc.clear_data_on_guild_remove(guild, "Your dir goes here.")


bot.run(TOKEN)


Documentation

You will here 'mute remove role' mentioned a lot. This is just an optional role that gets removed when a member is muted, and added back when they are unmuted.

Admin class

Kick:

async def kick(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, reason: typing.Optional[str] = None) -> None
import dpys

@bot.slash_command(name="kick")
@commands.has_permissions(kick_members=True)
async def kick(inter, member: disnake.Member = commands.Param(), reason: str = commands.Param(default=None)):
    await dpys.admin.kick(inter, member, reason)

Ban:

async def ban(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, reason: typing.Optional[str] = None) -> None
@bot.slash_command(name="ban")
@commands.has_permissions(ban_members=True)
async def ban(inter, member: disnake.Member = commands.Param(), reason: str = commands.Param(default=None)):
    await dpys.admin.ban(inter, member, reason)

Mute:

async def mute(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, role_add: int, role_remove: typing.Optional[int] = None, reason: str = None) -> None
@bot.slash_command(name="mute")
async def mute(inter, member: disnake.Member = commands.Param(), reason: str = commands.Param(default=None)):
    await dpys.admin.mute(inter, member, MUTE_ROLE_ID, MUTE_REMOVE_ROLE_ID, reason=reason)

Unmute:

async def unmute(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, role_remove: int, role_add: typing.Optional[int] = None) -> None
@bot.slash_command(name="unmute")
async def unmute(inter, member: disnake.Member = commands.Param()):
    await dpys.admin.unmute(inter, member, MUTE_REMOVE_ROLE_ID, MUTE_ROLE_ID)

Clear:

async def clear(inter: disnake.ApplicationCommandInteraction, amount: typing.Optional[int] = 99999999999999999) -> int
@bot.slash_command(name="clear")
async def clear(inter, amount: int = commands.Param(default=99999999999999999)):
    await dpys.admin.clear(inter, amount)

mute_on_join Class

Add Member:

async def mute_add(guild: disnake.Guild, member: disnake.Member, dir: str) -> None
@bot.slash_command(name="mute")
async def mute(inter, member: dicord.Member = commands.Param(), reason: str = commands.Param(default=None)):
	await dpys.admin.mute(inter, member, MUTE_ROLE_ID, MUTE_REMOVE_ROLE_ID, reason)
	await dpys.mute_on_join.mute_add(inter.guild, member, DIR)

Remove Member:

async def mute_remove(guild: disnake.Guild, member: disnake.Member, dir: str) -> None
@bot.slash_command(name="unmute")
async def unmute(inter, member: dicord.Member = commands.Param()):
	await dpys.admin.unmute(inter, member, MUTE_ROLE_ID, MUTE_REMOVE_ROLE_ID)
	await dpys.mute_on_join.mute_remove(inter.guild, member, DIR)

Mute On Join Event Listener:

async def mute_on_join(member: disnake.Member, role: int, dir: str) -> None
@bot.listen("on_member_join")
async def mute_on_join(member: disnake.Member):
	await dpys.mute_on_join.mute_on_join(member, MUTE_ROLE_ID, DIR)

Manual Unmute Check:

async def manual_unmute_check(after: disnake.Member, roleid: int, dir: str) -> None
import dpys
@bot.listen("on_member_update")
async def manual_unmute_check(before: disnake.Member, after: disnake.Member):
	await dpys.mute_on_join.manual_unmute_check(after, MUTE_ROLE_ID, DIR)

rr Class

Command:

async def command(inter: disnake.ApplicationCommandInteraction, emoji: str, dir: str, role: str, title: str, description: str) -> None
# Don't type hint disnake.Role for the role parameter
@bot.slash_command(name="rr")
async def reactionrole(inter, emoji: str = commands.Param(), role: str = commands.Param(), title: str = commands.Param(), description: str = commands.Param()):
    await dpys.rr.command(inter, emoji, DIR, role, title, description)

Command To List Reaction Roles:

async def display(inter: ApplicationCommandInteraction, dir: str) -> None
@bot.slash_command(name="listrr")
async def listrr(inter: disnake.ApplicationCommandInteraction):
    await dpys.rr.display(inter, DIR)

On Raw Reaction Add Event Listener:

async def add(payload: disnake.RawReactionActionEvent, dir: str, bot: commands.Bot) -> None
@bot.listen('on_raw_reaction_add')
async def rr_add(payload: disnake.RawReactionActionEvent):
    await dpys.rr.add(payload, DIR, bot)

On Raw Reaction Remove Event Listener:

async def remove(payload: disnake.RawReactionActionEvent, dir: str, bot: commands.Bot) -> None
@bot.listen('on_raw_reaction_remove')
async def rr_remove(payload: disnake.RawReactionActionEvent):
    await dpys.rr.remove(payload, DIR, bot)

Clear Reaction Role command:

async def clear_all(inter: disnake.ApplicationCommandInteraction, dir: str) -> None

async def clear_one(inter: disnake.ApplicationCommandInteraction, dir: str, message_id: int) -> None
@bot.slash_command(name="rrclear")
async def rrclear(inter, id : str = commands.Param()):
    if id.lower() == "all":
        await dpys.rr.clear_all(inter, DIR)
    else:
        await dpys.rr.clear_one(inter, DIR, id)

Event Listeners To Clear Reaction Role Data:

@bot.listen("on_message_delete")
async def rr_clear_on_message_delete(message: disnake.Message):
    await dpys.rr.clear_on_message_delete(message, DIR)


@bot.listen("on_raw_bulk_message_delete")
async def rr_clear_on_raw_bulk_message_delete(payload: disnake.RawBulkMessageDeleteEvent):
    await dpys.rr.clear_on_bulk_message_delete(payload, DIR)


@bot.listen("on_channel_delete")
async def rr_clear_on_channel_delete(channel: disnake.TextChannel):
    await dpys.rr.clear_on_channel_delete(channel, DIR)


@bot.listen("on_thread_delete")
async def rr_clear_on_thread_delete(thread: disnake.Thread):
    await dpys.rr.clear_on_thread_delete(thread, DIR)

warnings Class

Warn:

async def warn(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, dir: str, reason: typing.Optional[str] = None) -> None
@bot.slash_command(name="warn")
async def warn(inter: disnake.ApplicationCommandInteraction, member: disnake.Member = commands.Param(),
               reason: str = commands.Param(default=None)):
    await dpys.warnings.warn(inter, member, DIR, reason)

Unwarn:

async def unwarn(inter: disnake.ApplicationCommandInteraction, member, dir, number: typing.Union[int, str]) -> None
# Pass in "all" as the number parameter to clear all warnings from a member
@bot.slash_command(name="unwarn")
async def unwarn(inter: disnake.ApplicationCommandInteraction, member: disnake.Member = commands.Param(), number: str = commands.Param(default="all")):
	await dpys.warnings.unwarn(inter, member, DIR, number)

Punish:

async def punish(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, dir: str,
                     punishments: typing.List[typing.Optional[Punishment]],
                     add_role: typing.Optional[int] = None, remove_role: typing.Optional[int] = None) -> None
@bot.slash_command(name="warn")
async def warn(inter: disnake.ApplicationCommandInteraction, member: disnake.Member = commands.Param(),
               reason: str = commands.Param(default=None)):
    await dpys.warnings.warn(inter, member, DIR, reason)
    # This will do nothing for the first 2 warnibgs, but on the third warning it will kick the member.
    # Valid punishments for dpys.warnings.Punishment are kick, ban, mute, temp_ban, temp_mute
    # If you want to mute you have to pass in you mute role id and an optional mute remove role id.
    # For temporary punishments, a duration parameter can be passed into the dpys.warnings.Punishment constructor.
    # This is the number of seconds that the punishment will last.\
    await dpys.warnings.punish(inter, member, DIR,
                           [None, None, dpys.warnings.Punishment("kick")])

If you want to use temporary punishments, then include this cog in your bot.

from disnake.ext import commands, tasks

GET_MUTE_ROLE_ID = "an async function that takes in a guild id and returns the id for you mute role"
GET_MUTE_REMOVE_ROLE_ID = "an async function that takes in a guild id and returns the id for you mute remove role"

class DpysLoops(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        dpys_tempmute_loop.start()
        dpys_tempban_loop.start()
    
    @tasks.loop(seconds=1)
    async def dpys_tempmute_loop(self):
        await dpys.warnings.temp_mute_loop(DIR, self.bot, GET_MUTE_ROLE_ID, GET_MUTE_REMOVE_ROLE_ID)
    
        @dpys_tempmute_loop.before_loop
        async def before_dpys_tempmute_loop(self):
            await self.bot.wait_until_ready()
    
        @tasks.loop(seconds=1)
        async def dpys_tempban_loop(self):
            await dpys.warnings.temp_ban_loop(DIR, self.bot)
    
        @dpys_tempban_loop.before_loop
        async def before_dpys_tempban_loop(self):
            await self.bot.wait_until_ready()
            
def setup(bot):
    bot.add_cog(DpysLoops(bot))

Warnings:

async def warnings_list(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, dir: str) -> None
@bot.slash_command(name="warnings")
    async def warnings(inter: disnake.ApplicationCommandInteraction, member: disnake.Member = commands.Param()):
        await dpys.warnings.warnings_list(inter, member, DIR)

curse Class

Add Word:

async def add_banned_word(inter: disnake.ApplicationCommandInteraction, word: str, dir: str) -> None
@bot.slash_command(name="addword")
async def add_word(inter: disnake.ApplicationCommandInteraction, curses: str = commands.Param()):
    await dpys.curse.add_banned_word(inter, curses, DIR)

Remove Word:

async def remove_banned_word(inter: disnake.ApplicationCommandInteraction, word: str, dir: str) -> None
@bot.slash_command(name="removeword")
async def remove_word(inter: disnake.ApplicationCommandInteraction, curses: str = commands.Param()):
    await dpys.curse.remove_banned_word(inter, curses, DIR)

Clear Words:

async def clear_words(inter: disnake.ApplicationCommandInteraction, dir: str) -> None
@bot.slash_command(name="clearwords")
async def clear_words(inter: disnake.ApplicationCommandInteraction):
    await dpys.curse.clear_words(inter, DIR)

misc Class

Reload:

async def reload(inter: disnake.ApplicationCommandInteraction, bot: commands.Bot, cogs: typing.List[str]) -> None
@bot.slash_command(name="reload")
async def reload(inter: disnake.ApplicationCommandInteraction):
    cogs = ["cogs.admin", "cogs.fun", "cogs.misc"]
    await dpys.misc.reload(inter, bot, cogs)

Clear DPYS Data On Guild Remove:

@bot.listen("on_guild_remove")
async def clear_dpys_data(guild: disnake.Guild):
	await dpys.misc.clear_data_on_guild_remove(guild, DIR)

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dpys-5.2.7.tar.gz (16.8 kB view details)

Uploaded Source

File details

Details for the file dpys-5.2.7.tar.gz.

File metadata

  • Download URL: dpys-5.2.7.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for dpys-5.2.7.tar.gz
Algorithm Hash digest
SHA256 f36d2423a26e2442496cdc07e6ec34f5eb8a2ad3f7cef5a62e5f6bc87bcdb0ca
MD5 986dad50c791c1535c3a9c1863d0a4fa
BLAKE2b-256 1c11f163fe20d21f268124da8c42c1e5254cb589436cacc24ab2d80273154a8f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page