Package: dpys
DPYSThe 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
themhere.DPYSis 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
theaiosqlite library. Support for DPYS can be given
inour Discord server. If you see any problems in the code or want to add a
feature, create a pull request onour Github repository.Install from pypipython -m pip install dpysInstall from githubpython -m pip install git+https://github.com/JGLTechnologies/dpysSetupimportdpysfromdisnake.extimportcommandsbot=commands.AutoShardedBot(command_prefix="!")TOKEN="Your Token"bot.loop.create_task(dpys.setup(bot,"database directory"))bot.run()Reaction role exampleimportdpysfromdisnake.extimportcommandsimportdisnakebot=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")asyncdefreaction_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 DescriptionJust make sure to separate the emojis and roles with commas and match the position of the roles and emojis."""awaitdpys.rr.command(inter,emoji,role,title,description)# Adds role on reaction@bot.listen("on_raw_reaction_add")asyncdefrole_add(payload):awaitdpys.rr.add(payload,bot)# Removes role when reaction is removed@bot.listen("on_raw_reaction_remove")asyncdefrole_remove(payload):awaitdpys.rr.remove(payload,bot)# Command to list all current reaction roles in the guild@bot.slash_command(name="listrr")asyncdeflistrr(inter:disnake.ApplicationCommandInteraction):awaitdpys.rr.display(inter)# Command to remove reaction role info from the database@bot.slash_command(name="rrclear")asyncdefrrclear(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()ifid=="all":awaitdpys.rr.clear_all(inter)else:awaitdpys.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")asyncdefrr_clear_on_message_delete(message):awaitdpys.rr.clear_on_message_delete(message)# Removes data for a reaction role when its channel is deleted@bot.listen("on_channel_delete")asyncdefrr_clear_on_channel_delete(channel):awaitdpys.rr.clear_on_channel_delete(channel)# Removes data for a reaction role when its thread is deleted@bot.listen("on_thread_delete")asyncdefrr_clear_on_thread_delete(thread):awaitdpys.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")asyncdefrr_clear_on_raw_bulk_message_delete(payload):awaitdpys.rr.clear_on_raw_bulk_message_delete(payload)# Clears all DPYS data for a guild when it is removed@bot.listen("on_guild_remove")asyncdefclear_on_guild_remove(guild):awaitdpys.misc.clear_data_on_guild_remove(guild)bot.loop.create_task(dpys.setup(bot,DIR))bot.run(TOKEN)DocumentationYou 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 classKick:asyncdefkick(inter:disnake.ApplicationCommandInteraction,member:disnake.Member,reason:typing.Optional[str]=None,msg:str=None)->Noneimportdpys@bot.slash_command(name="kick")@commands.has_permissions(kick_members=True)asyncdefkick(inter,member:disnake.Member=commands.Param(),reason:str=commands.Param(default=None)):awaitdpys.admin.kick(inter,member,reason)Ban:asyncdefban(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)asyncdefban(inter,member:disnake.Member=commands.Param(),reason:str=commands.Param(default=None)):awaitdpys.admin.ban(inter,member,reason)Softban:asyncdefsoftban(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)asyncdefsoftban(inter,member:disnake.Member=commands.Param(),reason:str=commands.Param(default=None)):awaitdpys.admin.softban(inter,member,reason)Unban:asyncdefunban(inter:ApplicationCommandInteraction,member:typing.Union[str,int],msg:str=None)->bool:@bot.slash_command(name="unban")@commands.has_permissions(ban_members=True)asyncdefunban(inter,member:string=commands.Param()):awaitdpys.admin.unban(inter,member)Mute:asyncdefmute(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")asyncdefmute(inter,member:disnake.Member=commands.Param(),reason:str=commands.Param(default=None)):awaitdpys.admin.mute(inter,member,MUTE_ROLE_ID,MUTE_REMOVE_ROLE_ID,reason=reason)Unmute:asyncdefunmute(inter:disnake.ApplicationCommandInteraction,member:disnake.Member,role_remove:int,role_add:typing.Optional[int]=None,msg:str=None)->bool@bot.slash_command(name="unmute")asyncdefunmute(inter,member:disnake.Member=commands.Param()):awaitdpys.admin.unmute(inter,member,MUTE_REMOVE_ROLE_ID,MUTE_ROLE_ID)Clear:asyncdefclear(inter:disnake.ApplicationCommandInteraction,amount:typing.Optional[int]=99999999999999999,msg:str=None)->int@bot.slash_command(name="clear")asyncdefclear(inter,amount:int=commands.Param(default=99999999999999999)):awaitdpys.admin.clear(inter,amount)Timeout:asyncdeftimeout(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")asyncdeftimeout(inter,seconds:int=commands.Param(),reason:str=commands.Param(None)):awaitdpys.admin.timeout(inter,duration=seconds,reason=reason)mute_on_join ClassAdd Member:asyncdefmute_add(guild:disnake.Guild,member:disnake.Member)->None@bot.slash_command(name="mute")asyncdefmute(inter,member:dicord.Member=commands.Param(),reason:str=commands.Param(default=None)):awaitdpys.admin.mute(inter,member,MUTE_ROLE_ID,MUTE_REMOVE_ROLE_ID,reason)awaitdpys.mute_on_join.mute_add(inter.guild,member)Remove Member:asyncdefmute_remove(guild:disnake.Guild,member:disnake.Member)->None@bot.slash_command(name="unmute")asyncdefunmute(inter,member:dicord.Member=commands.Param()):awaitdpys.admin.unmute(inter,member,MUTE_ROLE_ID,MUTE_REMOVE_ROLE_ID)awaitdpys.mute_on_join.mute_remove(inter.guild,member)Mute On Join Event Listener:asyncdefmute_on_join(member:disnake.Member,role:int)->None@bot.listen("on_member_join")asyncdefmute_on_join(member:disnake.Member):awaitdpys.mute_on_join.mute_on_join(member,MUTE_ROLE_ID)Manual Unmute Check:asyncdefmanual_unmute_check(after:disnake.Member,roleid:int)->Noneimportdpys@bot.listen("on_member_update")asyncdefmanual_unmute_check(before:disnake.Member,after:disnake.Member):awaitdpys.mute_on_join.manual_unmute_check(after,MUTE_ROLE_ID)rr ClassCommand:asyncdefcommand(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")asyncdefreactionrole(inter,emoji:str=commands.Param(),role:str=commands.Param(),title:str=commands.Param(),description:str=commands.Param()):awaitdpys.rr.command(inter,emoji,role,title,description)Command To List Reaction Roles:asyncdefdisplay(inter:ApplicationCommandInteraction)->None@bot.slash_command(name="listrr")asyncdeflistrr(inter:disnake.ApplicationCommandInteraction):awaitdpys.rr.display(inter)On Raw Reaction Add Event Listener:asyncdefadd(payload:disnake.RawReactionActionEvent,bot:commands.Bot)->None@bot.listen('on_raw_reaction_add')asyncdefrr_add(payload:disnake.RawReactionActionEvent):awaitdpys.rr.add(payload,bot)On Raw Reaction Remove Event Listener:asyncdefremove(payload:disnake.RawReactionActionEvent,bot:commands.Bot)->None@bot.listen('on_raw_reaction_remove')asyncdefrr_remove(payload:disnake.RawReactionActionEvent):awaitdpys.rr.remove(payload,bot)Clear Reaction Role command:asyncdefclear_all(inter:disnake.ApplicationCommandInteraction)->Noneasyncdefclear_one(inter:disnake.ApplicationCommandInteraction,message_id:int)->None@bot.slash_command(name="rrclear")asyncdefrrclear(inter,id:str=commands.Param()):ifid.lower()=="all":awaitdpys.rr.clear_all(inter)else:awaitdpys.rr.clear_one(inter,id)Event Listeners To Clear Reaction Role Data:@bot.listen("on_message_delete")asyncdefrr_clear_on_message_delete(message:disnake.Message):awaitdpys.rr.clear_on_message_delete(message)@bot.listen("on_raw_bulk_message_delete")asyncdefrr_clear_on_raw_bulk_message_delete(payload:disnake.RawBulkMessageDeleteEvent):awaitdpys.rr.clear_on_bulk_message_delete(payload)@bot.listen("on_channel_delete")asyncdefrr_clear_on_channel_delete(channel:disnake.TextChannel):awaitdpys.rr.clear_on_channel_delete(channel)@bot.listen("on_thread_delete")asyncdefrr_clear_on_thread_delete(thread:disnake.Thread):awaitdpys.rr.clear_on_thread_delete(thread)warnings ClassWarn:asyncdefwarn(inter:ApplicationCommandInteraction,member:discord.Member,reason:typing.Optional[str]=None,expires:Optional[int]=-1)->None:@bot.slash_command(name="warn")asyncdefwarn(inter:disnake.ApplicationCommandInteraction,member:disnake.Member=commands.Param(),reason:str=commands.Param(default=None)):# Warning will expire in 1 dayawaitdpys.warnings.warn(inter,member,reason,time.now()+86400)Unwarn:asyncdefunwarn(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")asyncdefunwarn(inter:disnake.ApplicationCommandInteraction,member:disnake.Member=commands.Param(),number:str=commands.Param(default="all")):awaitdpys.warnings.unwarn(inter,member,number)Punish:asyncdefpunish(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")asyncdefwarn(inter:disnake.ApplicationCommandInteraction,member:disnake.Member=commands.Param(),reason:str=commands.Param(default=None)):awaitdpys.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.awaitdpys.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.fromdisnake.extimportcommands,tasksimportdpysGET_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"classDpysLoops(commands.Cog):def__init__(self,bot):self.bot=botself.dpys_tempmute_loop.start()self.dpys_tempban_loop.start()@tasks.loop(seconds=1)asyncdefdpys_tempmute_loop(self):awaitdpys.warnings.temp_mute_loop(self.bot,GET_MUTE_ROLE_ID,GET_MUTE_REMOVE_ROLE_ID)@dpys_tempmute_loop.before_loopasyncdefbefore_dpys_tempmute_loop(self):awaitself.bot.wait_until_ready()@tasks.loop(minutes=30)asyncdefdpys_expire(self):awaitdpys.warnings.expire_loop()@dpys_expire.before_loopasyncdefbefore_dpys_tempmute_loop(self):awaitself.bot.wait_until_ready()@tasks.loop(seconds=1)asyncdefdpys_tempban_loop(self):awaitdpys.warnings.temp_ban_loop(self.bot)@dpys_tempban_loop.before_loopasyncdefbefore_dpys_tempban_loop(self):awaitself.bot.wait_until_ready()defsetup(bot):bot.add_cog(DpysLoops(bot))Warnings:asyncdefwarnings_list(inter:disnake.ApplicationCommandInteraction,member:disnake.Member)->None@bot.slash_command(name="warnings")asyncdefwarnings(inter:disnake.ApplicationCommandInteraction,member:disnake.Member=commands.Param()):awaitdpys.warnings.warnings_list(inter,member)curse ClassAdd Word:asyncdefadd_banned_word(inter:disnake.ApplicationCommandInteraction,word:str)->None@bot.slash_command(name="addword")asyncdefadd_word(inter:disnake.ApplicationCommandInteraction,curses:str=commands.Param()):awaitdpys.curse.add_banned_word(inter,curses)Remove Word:asyncdefremove_banned_word(inter:disnake.ApplicationCommandInteraction,word:str)->None@bot.slash_command(name="removeword")asyncdefremove_word(inter:disnake.ApplicationCommandInteraction,curses:str=commands.Param()):awaitdpys.curse.remove_banned_word(inter,curses)Clear Words:asyncdefclear_words(inter:disnake.ApplicationCommandInteraction)->None@bot.slash_command(name="clearwords")asyncdefclear_words(inter:disnake.ApplicationCommandInteraction):awaitdpys.curse.clear_words(inter)misc ClassReload:asyncdefreload(inter:disnake.ApplicationCommandInteraction,bot:commands.Bot,cogs:typing.List[str])->None@bot.slash_command(name="reload")asyncdefreload(inter:disnake.ApplicationCommandInteraction):cogs=["cogs.admin","cogs.fun","cogs.misc"]awaitdpys.misc.reload(inter,bot,cogs)Clear DPYS Data On Guild Remove:@bot.listen("on_guild_remove")asyncdefclear_dpys_data(guild:disnake.Guild):awaitdpys.misc.clear_data_on_guild_remove(guild)