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

Setup


import dpys
from disnake.ext import commands

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

bot.loop.create_task(dpys.setup(bot, "database directory"))
bot.run()

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
@bot.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, role, title, description
    )


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


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


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


# Command to remove reaction role info from the database
@bot.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)
    else:
        await dpys.rr.clear_one(inter, 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)


# 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)


# 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)


# 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)


# 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)


bot.loop.create_task(dpys.setup(bot, DIR))
bot.run(TOKEN)


Documentation

You will hear '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, msg: 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, msg: 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)

Softban:

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

Unban:

async def unban(inter: ApplicationCommandInteraction, member: typing.Union[str, int], msg: str = None) -> bool:
@bot.slash_command(name="unban")
@commands.has_permissions(ban_members=True)
async def unban(inter, member: string = commands.Param()):
    await dpys.admin.unban(inter, member)

Mute:

async def mute(inter: disnake.ApplicationCommandInteraction, member: disnake.Member, role_add: int,
               role_remove: typing.Optional[int] = None, reason: str = None, msg: 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, msg: str = None) -> bool
@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,
                msg: str = None) -> int
@bot.slash_command(name="clear")
async def clear(inter, amount: int = commands.Param(default=99999999999999999)):
    await dpys.admin.clear(inter, amount)

Timeout:

async def timeout(inter: ApplicationCommandInteraction, member: discord.Member,
                  duration: Union[float, datetime.timedelta] = None, until: datetime.datetime = None,
                  reason: typing.Optional[str] = None, msg: str = None) -> None:
@bot.slash_command(name="timeout")
async def timeout(inter, seconds: int = commands.Param(), reason: str = commands.Param(None)):
    await dpys.admin.timeout(inter, duration=seconds, reason=reason)

mute_on_join Class

Add Member:

async def mute_add(guild: disnake.Guild, member: disnake.Member) -> 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)

Remove Member:

async def mute_remove(guild: disnake.Guild, member: disnake.Member) -> 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)

Mute On Join Event Listener:

async def mute_on_join(member: disnake.Member, role: int) -> 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)

Manual Unmute Check:

async def manual_unmute_check(after: disnake.Member, roleid: int) -> 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)

rr Class

Command:

async def command(inter: disnake.ApplicationCommandInteraction, emoji: 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, role, title, description)

Command To List Reaction Roles:

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

On Raw Reaction Add Event Listener:

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

On Raw Reaction Remove Event Listener:

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

Clear Reaction Role command:

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


async def clear_one(inter: disnake.ApplicationCommandInteraction, 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)
    else:
        await dpys.rr.clear_one(inter, 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)


@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)


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


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

warnings Class

Warn:

async def warn(inter: ApplicationCommandInteraction, member: discord.Member,
                   reason: typing.Optional[str] = None, expires: Optional[int] = -1) -> None:
@bot.slash_command(name="warn")
async def warn(inter: disnake.ApplicationCommandInteraction, member: disnake.Member = commands.Param(),
               reason: str = commands.Param(default=None)):
    # Warning will expire in 1 day
    await dpys.warnings.warn(inter, member, reason, time.now() + 86400)

Unwarn:

async def unwarn(inter: disnake.ApplicationCommandInteraction, member, dir, number: typing.Union[int, str]) -> bool
# 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, number)

Punish:

async def punish(inter: ApplicationCommandInteraction, member: discord.Member,
                 punishments: typing.Mapping[int, Punishment],
                 add_role: typing.Optional[int] = None, remove_role: typing.Optional[int] = None,
                 before: Optional[
                     Callable[[int, Punishment, discord.Member], Awaitable[Optional[Member]]]] = 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, reason)
    # This will do nothing for the first 2 warnings, but on the third warning it will kick the member.
    # Valid punishments for dpys.warnings.Punishment are kick, ban, mute, temp_ban, temp_mute, timeout
    # 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,
                               {3: dpys.warnings.Punishment("kick")})

If you want to use temp_ban or temp_mute, then include this cog in your bot.

from disnake.ext import commands, tasks
import dpys

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


class DpysLoops(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        self.dpys_tempmute_loop.start()
        self.dpys_tempban_loop.start()

    @tasks.loop(seconds=1)
    async def dpys_tempmute_loop(self):
        await dpys.warnings.temp_mute_loop(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(minutes=30)
    async def dpys_expire(self):
        await dpys.warnings.expire_loop()
        
    @dpys_expire.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(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) -> None
@bot.slash_command(name="warnings")
async def warnings(inter: disnake.ApplicationCommandInteraction, member: disnake.Member = commands.Param()):
    await dpys.warnings.warnings_list(inter, member)

curse Class

Add Word:

async def add_banned_word(inter: disnake.ApplicationCommandInteraction, word: 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)

Remove Word:

async def remove_banned_word(inter: disnake.ApplicationCommandInteraction, word: 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)

Clear Words:

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

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)

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.5.9.tar.gz (17.6 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: dpys-5.5.9.tar.gz
  • Upload date:
  • Size: 17.6 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.6

File hashes

Hashes for dpys-5.5.9.tar.gz
Algorithm Hash digest
SHA256 9e5ef06d5a6d3065079aa99ab010ce454cfaf247035803d080901b2e39d97f67
MD5 2a45d32b47fe8f6435bb00dac16e147c
BLAKE2b-256 7ecdb4cec524608c17c0e607a0ef3501f2bfad91603be32d805e3653e9dcc8fd

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