Spaces:
Sleeping
Sleeping
Rifat Azad commited on
Commit ·
7f5c15c
1
Parent(s): ca908a9
new moderator commands update 1.2.0
Browse files- pydvpl_bot.py +158 -5
pydvpl_bot.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import json
|
|
|
|
| 4 |
import psutil
|
| 5 |
import discord
|
| 6 |
from dotenv import load_dotenv
|
|
@@ -21,7 +22,7 @@ load_dotenv()
|
|
| 21 |
# DEFINES ------------------------------------------------------ START
|
| 22 |
|
| 23 |
|
| 24 |
-
BOT_VERSION = '1.
|
| 25 |
|
| 26 |
AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
|
| 27 |
|
|
@@ -299,6 +300,7 @@ async def help(ctx):
|
|
| 299 |
embed.add_field(name="PyDVPL Prefix:", value="`/` - Discord's slash command prefix.\n`>>` - PyDVPL default prefix.")
|
| 300 |
embed.add_field(name="Dvpl Commands:", value="`compress` - Compresses files.\n`decompress` - Decompresses files.", inline=False)
|
| 301 |
embed.add_field(name="User Utility Commands:", value="`ping` - Checks the bot's latency.\n`invite` - Get the bot's invite link.\n`uptime` - Displays the bot's uptime.", inline=False)
|
|
|
|
| 302 |
embed.add_field(name="Admin Utility Commands:", value="`stats` - Displays bot statistics.\n`list` - Lists server members.\n`say` - Make the bot say something.\n`announce` - Announces a message to a channel.\n`activity` - Sets bot activity status.\n`online` - Sets bot status to online.\n`dnd` - Sets bot status to Do Not Disturb.\n`offline` - Sets bot status to offline.\n`clean` - Cleans up bot's messages.", inline=False)
|
| 303 |
embed.add_field(name="Feedback Commands:", value="`feedback` - Sends feedback to bot developers. (usage: >>feedback issues/requests <message>)", inline=False)
|
| 304 |
|
|
@@ -399,12 +401,17 @@ async def invite(ctx):
|
|
| 399 |
permissions = discord.Permissions(
|
| 400 |
read_messages=True,
|
| 401 |
send_messages=True,
|
| 402 |
-
embed_links=True,
|
| 403 |
attach_files=True,
|
| 404 |
read_message_history=True,
|
| 405 |
mention_everyone=True,
|
| 406 |
add_reactions=True,
|
| 407 |
manage_guild=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
)
|
| 409 |
|
| 410 |
client_id = bot.user.id
|
|
@@ -504,6 +511,7 @@ async def version(ctx):
|
|
| 504 |
|
| 505 |
@bot.hybrid_command(help="Cleans files in specific directories")
|
| 506 |
async def clean(ctx, clean_mode):
|
|
|
|
| 507 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 508 |
await ctx.send("You are not authorized to use this command.")
|
| 509 |
|
|
@@ -526,6 +534,7 @@ async def clean(ctx, clean_mode):
|
|
| 526 |
|
| 527 |
@bot.hybrid_command(help="Set bot's presence to online")
|
| 528 |
async def online(ctx):
|
|
|
|
| 529 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 530 |
await ctx.send("You are not authorized to use this command.")
|
| 531 |
|
|
@@ -540,6 +549,7 @@ async def online(ctx):
|
|
| 540 |
|
| 541 |
@bot.hybrid_command(help="Set bot's presence to Do Not Disturb")
|
| 542 |
async def dnd(ctx):
|
|
|
|
| 543 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 544 |
await ctx.send("You are not authorized to use this command.")
|
| 545 |
|
|
@@ -554,6 +564,7 @@ async def dnd(ctx):
|
|
| 554 |
|
| 555 |
@bot.hybrid_command(help="Set bot's presence to offline")
|
| 556 |
async def offline(ctx):
|
|
|
|
| 557 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 558 |
await ctx.send("You are not authorized to use this command.")
|
| 559 |
|
|
@@ -568,6 +579,7 @@ async def offline(ctx):
|
|
| 568 |
|
| 569 |
@bot.hybrid_command(help="Set bot's activity")
|
| 570 |
async def activity(ctx, activity_type, *, activity_text=None):
|
|
|
|
| 571 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 572 |
await ctx.send("You are not authorized to use this command.")
|
| 573 |
|
|
@@ -599,7 +611,7 @@ async def activity(ctx, activity_type, *, activity_text=None):
|
|
| 599 |
|
| 600 |
@bot.hybrid_command(help="Send messages to specific channels or users")
|
| 601 |
async def say(ctx, destination_type, *, id, message):
|
| 602 |
-
|
| 603 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 604 |
await ctx.send("You are not authorized to use this command.")
|
| 605 |
return
|
|
@@ -675,12 +687,13 @@ async def say(ctx, destination_type, *, id, message):
|
|
| 675 |
|
| 676 |
@bot.hybrid_command(help="Send announcements to all servers")
|
| 677 |
async def announce(ctx, *, message):
|
|
|
|
| 678 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 679 |
await ctx.send("You are not authorized to use this command.")
|
| 680 |
|
| 681 |
return
|
| 682 |
|
| 683 |
-
embed = discord.Embed(title="Announcement", description=message, color=discord.Color.yellow())
|
| 684 |
|
| 685 |
for server in bot.guilds:
|
| 686 |
# First, check for an "important-announcements" channel
|
|
@@ -717,7 +730,7 @@ async def announce(ctx, *, message):
|
|
| 717 |
|
| 718 |
@bot.hybrid_command(help="Show statistics about bot's health and connection.")
|
| 719 |
async def stats(ctx):
|
| 720 |
-
|
| 721 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 722 |
await ctx.send("You are not authorized to use this command.")
|
| 723 |
|
|
@@ -752,9 +765,12 @@ async def stats(ctx):
|
|
| 752 |
await ctx.send(stats_message)
|
| 753 |
|
| 754 |
|
|
|
|
|
|
|
| 755 |
|
| 756 |
@bot.hybrid_command(help="List issues, requests, or servers")
|
| 757 |
async def list(ctx, list_type):
|
|
|
|
| 758 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 759 |
await ctx.send("You are not authorized to use this command.")
|
| 760 |
|
|
@@ -772,6 +788,143 @@ async def list(ctx, list_type):
|
|
| 772 |
await ctx.send("Invalid list type. Please choose 'servers', 'issues', or 'requests'.")
|
| 773 |
|
| 774 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 775 |
# UTILITY ADMIN_CMD ------------------------------------------------------ END
|
| 776 |
|
| 777 |
|
|
|
|
| 1 |
import os
|
| 2 |
import time
|
| 3 |
import json
|
| 4 |
+
import asyncio
|
| 5 |
import psutil
|
| 6 |
import discord
|
| 7 |
from dotenv import load_dotenv
|
|
|
|
| 22 |
# DEFINES ------------------------------------------------------ START
|
| 23 |
|
| 24 |
|
| 25 |
+
BOT_VERSION = '1.2.0'
|
| 26 |
|
| 27 |
AUTHORIZED_USER_ID = os.getenv('AUTHORIZED_ID')
|
| 28 |
|
|
|
|
| 300 |
embed.add_field(name="PyDVPL Prefix:", value="`/` - Discord's slash command prefix.\n`>>` - PyDVPL default prefix.")
|
| 301 |
embed.add_field(name="Dvpl Commands:", value="`compress` - Compresses files.\n`decompress` - Decompresses files.", inline=False)
|
| 302 |
embed.add_field(name="User Utility Commands:", value="`ping` - Checks the bot's latency.\n`invite` - Get the bot's invite link.\n`uptime` - Displays the bot's uptime.", inline=False)
|
| 303 |
+
embed.add_field(name="Moderator Commands:", value="`kick` - Kick a member from the server.\n`ban` - Ban a member from the server.\n`timeout` - Timeout a member for a specified duration.", inline=False)
|
| 304 |
embed.add_field(name="Admin Utility Commands:", value="`stats` - Displays bot statistics.\n`list` - Lists server members.\n`say` - Make the bot say something.\n`announce` - Announces a message to a channel.\n`activity` - Sets bot activity status.\n`online` - Sets bot status to online.\n`dnd` - Sets bot status to Do Not Disturb.\n`offline` - Sets bot status to offline.\n`clean` - Cleans up bot's messages.", inline=False)
|
| 305 |
embed.add_field(name="Feedback Commands:", value="`feedback` - Sends feedback to bot developers. (usage: >>feedback issues/requests <message>)", inline=False)
|
| 306 |
|
|
|
|
| 401 |
permissions = discord.Permissions(
|
| 402 |
read_messages=True,
|
| 403 |
send_messages=True,
|
| 404 |
+
embed_links=True,
|
| 405 |
attach_files=True,
|
| 406 |
read_message_history=True,
|
| 407 |
mention_everyone=True,
|
| 408 |
add_reactions=True,
|
| 409 |
manage_guild=True,
|
| 410 |
+
ban_members=True,
|
| 411 |
+
kick_members=True,
|
| 412 |
+
moderate_members=True,
|
| 413 |
+
use_application_commands=True,
|
| 414 |
+
manage_roles=True
|
| 415 |
)
|
| 416 |
|
| 417 |
client_id = bot.user.id
|
|
|
|
| 511 |
|
| 512 |
@bot.hybrid_command(help="Cleans files in specific directories")
|
| 513 |
async def clean(ctx, clean_mode):
|
| 514 |
+
# Check if the author is authorized to use this command
|
| 515 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 516 |
await ctx.send("You are not authorized to use this command.")
|
| 517 |
|
|
|
|
| 534 |
|
| 535 |
@bot.hybrid_command(help="Set bot's presence to online")
|
| 536 |
async def online(ctx):
|
| 537 |
+
# Check if the author is authorized to use this command
|
| 538 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 539 |
await ctx.send("You are not authorized to use this command.")
|
| 540 |
|
|
|
|
| 549 |
|
| 550 |
@bot.hybrid_command(help="Set bot's presence to Do Not Disturb")
|
| 551 |
async def dnd(ctx):
|
| 552 |
+
# Check if the author is authorized to use this command
|
| 553 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 554 |
await ctx.send("You are not authorized to use this command.")
|
| 555 |
|
|
|
|
| 564 |
|
| 565 |
@bot.hybrid_command(help="Set bot's presence to offline")
|
| 566 |
async def offline(ctx):
|
| 567 |
+
# Check if the author is authorized to use this command
|
| 568 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 569 |
await ctx.send("You are not authorized to use this command.")
|
| 570 |
|
|
|
|
| 579 |
|
| 580 |
@bot.hybrid_command(help="Set bot's activity")
|
| 581 |
async def activity(ctx, activity_type, *, activity_text=None):
|
| 582 |
+
# Check if the author is authorized to use this command
|
| 583 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 584 |
await ctx.send("You are not authorized to use this command.")
|
| 585 |
|
|
|
|
| 611 |
|
| 612 |
@bot.hybrid_command(help="Send messages to specific channels or users")
|
| 613 |
async def say(ctx, destination_type, *, id, message):
|
| 614 |
+
# Check if the author is authorized to use this command
|
| 615 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 616 |
await ctx.send("You are not authorized to use this command.")
|
| 617 |
return
|
|
|
|
| 687 |
|
| 688 |
@bot.hybrid_command(help="Send announcements to all servers")
|
| 689 |
async def announce(ctx, *, message):
|
| 690 |
+
# Check if the author is authorized to use this command
|
| 691 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 692 |
await ctx.send("You are not authorized to use this command.")
|
| 693 |
|
| 694 |
return
|
| 695 |
|
| 696 |
+
embed = discord.Embed(title="Announcement!", description=message, color=discord.Color.yellow())
|
| 697 |
|
| 698 |
for server in bot.guilds:
|
| 699 |
# First, check for an "important-announcements" channel
|
|
|
|
| 730 |
|
| 731 |
@bot.hybrid_command(help="Show statistics about bot's health and connection.")
|
| 732 |
async def stats(ctx):
|
| 733 |
+
# Check if the author is authorized to use this command
|
| 734 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 735 |
await ctx.send("You are not authorized to use this command.")
|
| 736 |
|
|
|
|
| 765 |
await ctx.send(stats_message)
|
| 766 |
|
| 767 |
|
| 768 |
+
# FUNCTION ------------------------------------------------------ SPLIT
|
| 769 |
+
|
| 770 |
|
| 771 |
@bot.hybrid_command(help="List issues, requests, or servers")
|
| 772 |
async def list(ctx, list_type):
|
| 773 |
+
# Check if the author is authorized to use this command
|
| 774 |
if str(ctx.author.id) != AUTHORIZED_USER_ID:
|
| 775 |
await ctx.send("You are not authorized to use this command.")
|
| 776 |
|
|
|
|
| 788 |
await ctx.send("Invalid list type. Please choose 'servers', 'issues', or 'requests'.")
|
| 789 |
|
| 790 |
|
| 791 |
+
# FUNCTION ------------------------------------------------------ SPLIT
|
| 792 |
+
|
| 793 |
+
|
| 794 |
+
@bot.hybrid_command(help="Kick a member from the server.")
|
| 795 |
+
async def kick(ctx, member: discord.Member, *, reason=None):
|
| 796 |
+
# Check if the author is owner of the guild to use this command
|
| 797 |
+
if ctx.author.guild_permissions.kick_members or ctx.author == ctx.guild.owner:
|
| 798 |
+
|
| 799 |
+
if ctx.author.top_role > member.top_role:
|
| 800 |
+
|
| 801 |
+
# Send a DM to the kicked member
|
| 802 |
+
dm_message = f"You have been kicked from the server `{ctx.guild.name}`"
|
| 803 |
+
if reason:
|
| 804 |
+
dm_message += f" for the following reason: `{reason}`"
|
| 805 |
+
try:
|
| 806 |
+
await member.send(dm_message)
|
| 807 |
+
except discord.Forbidden:
|
| 808 |
+
await ctx.send(f"Failed to send DM to `{member}` for kick.")
|
| 809 |
+
|
| 810 |
+
# Kick the member from the server
|
| 811 |
+
try:
|
| 812 |
+
await member.kick(reason=reason)
|
| 813 |
+
await ctx.send(f"`{member}` has been kicked from the server. Reason: `{reason}`")
|
| 814 |
+
except discord.Forbidden:
|
| 815 |
+
await ctx.send("I don't have permission to kick this member.")
|
| 816 |
+
|
| 817 |
+
else:
|
| 818 |
+
await ctx.send("You do not have permission to kick this member.")
|
| 819 |
+
|
| 820 |
+
else:
|
| 821 |
+
await ctx.send("You do not have permission to use this command.")
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
# FUNCTION ------------------------------------------------------ SPLIT
|
| 825 |
+
|
| 826 |
+
|
| 827 |
+
@bot.hybrid_command(help="Ban a member from the server.")
|
| 828 |
+
async def ban(ctx, member: discord.Member, *, reason=None):
|
| 829 |
+
# Check if the author is owner of the guild to use this command
|
| 830 |
+
if ctx.author.guild_permissions.ban_members or ctx.author == ctx.guild.owner:
|
| 831 |
+
|
| 832 |
+
if ctx.author.top_role > member.top_role:
|
| 833 |
+
|
| 834 |
+
# Send a DM to the banned member
|
| 835 |
+
dm_message = f"You have been banned from the server `{ctx.guild.name}`"
|
| 836 |
+
if reason:
|
| 837 |
+
dm_message += f" for the following reason: `{reason}`"
|
| 838 |
+
try:
|
| 839 |
+
await member.send(dm_message)
|
| 840 |
+
except discord.Forbidden:
|
| 841 |
+
await ctx.send(f"Failed to send DM to `{member}` for ban.")
|
| 842 |
+
|
| 843 |
+
# Ban the member from the server
|
| 844 |
+
try:
|
| 845 |
+
await member.ban(reason=reason)
|
| 846 |
+
await ctx.send(f"`{member}` has been banned from the server. Reason: `{reason}`")
|
| 847 |
+
except discord.Forbidden:
|
| 848 |
+
await ctx.send("I don't have permission to ban this member.")
|
| 849 |
+
|
| 850 |
+
else:
|
| 851 |
+
await ctx.send("You do not have permission to ban this member.")
|
| 852 |
+
|
| 853 |
+
else:
|
| 854 |
+
await ctx.send("You do not have permission to use this command.")
|
| 855 |
+
|
| 856 |
+
|
| 857 |
+
# FUNCTION ------------------------------------------------------ SPLIT
|
| 858 |
+
|
| 859 |
+
|
| 860 |
+
|
| 861 |
+
@bot.hybrid_command(help="Timeout a member for a specified duration.")
|
| 862 |
+
async def timeout(ctx, member: discord.Member, duration: int, *, reason=None):
|
| 863 |
+
|
| 864 |
+
# Check if the author is owner of the guild to use this command
|
| 865 |
+
if ctx.author.guild_permissions.manage_roles or ctx.author == ctx.guild.owner:
|
| 866 |
+
|
| 867 |
+
# Check if the bot has permission to manage roles
|
| 868 |
+
if not ctx.guild.me.guild_permissions.manage_roles:
|
| 869 |
+
await ctx.send("I don't have permission to manage roles.")
|
| 870 |
+
return
|
| 871 |
+
|
| 872 |
+
# Check if the author has a higher role than the member being timed out
|
| 873 |
+
if ctx.author.top_role <= member.top_role:
|
| 874 |
+
await ctx.send("You do not have permission to timeout this member.")
|
| 875 |
+
return
|
| 876 |
+
|
| 877 |
+
try:
|
| 878 |
+
# Duration in seconds
|
| 879 |
+
timeout_duration = duration
|
| 880 |
+
|
| 881 |
+
# Timeout the member by removing all roles
|
| 882 |
+
await member.edit(roles=[], reason=reason)
|
| 883 |
+
|
| 884 |
+
await ctx.send(f"`{member}` has been timed out for `{duration} seconds`. Reason: `{reason}`")
|
| 885 |
+
|
| 886 |
+
# Construct the message to be sent as a DM
|
| 887 |
+
dm_message_init = f"You have been timed out in the server `{ctx.guild.name}` for `{duration} seconds`"
|
| 888 |
+
if reason:
|
| 889 |
+
dm_message_init += f" for the following reason: `{reason}`"
|
| 890 |
+
|
| 891 |
+
# Send a DM to the timed-out member
|
| 892 |
+
try:
|
| 893 |
+
await member.send(dm_message_init)
|
| 894 |
+
except discord.Forbidden:
|
| 895 |
+
# If unable to send DM, log the error and continue
|
| 896 |
+
await ctx.send(f"Failed to send DM to `{member}` for timeout.")
|
| 897 |
+
|
| 898 |
+
except Exception as e:
|
| 899 |
+
await ctx.send(f"An error occurred: {e}")
|
| 900 |
+
return # Stop execution if there's an error
|
| 901 |
+
|
| 902 |
+
# Wait for the duration of the timeout
|
| 903 |
+
await asyncio.sleep(timeout_duration)
|
| 904 |
+
|
| 905 |
+
# Restore the member's roles after the timeout
|
| 906 |
+
try:
|
| 907 |
+
await member.edit(roles=member.roles, reason=reason)
|
| 908 |
+
except Exception as e:
|
| 909 |
+
print(f"An error occurred while restoring roles to `{member}`: {e}")
|
| 910 |
+
return # Stop execution if there's an error
|
| 911 |
+
|
| 912 |
+
dm_message_exit = f"Your previous timeout in the server `{ctx.guild.name}` for `{duration} seconds`"
|
| 913 |
+
if reason:
|
| 914 |
+
dm_message_exit += f" for the following reason: `{reason}` has been expired!"
|
| 915 |
+
|
| 916 |
+
try:
|
| 917 |
+
await member.send(dm_message_exit)
|
| 918 |
+
except discord.Forbidden:
|
| 919 |
+
# If unable to send DM, log the error and continue
|
| 920 |
+
await ctx.send(f"Failed to send DM to `{member}` to notify timeout expiration.")
|
| 921 |
+
|
| 922 |
+
else:
|
| 923 |
+
await ctx.send("You do not have permission to use this command.")
|
| 924 |
+
|
| 925 |
+
|
| 926 |
+
|
| 927 |
+
|
| 928 |
# UTILITY ADMIN_CMD ------------------------------------------------------ END
|
| 929 |
|
| 930 |
|