From a08029000c464c9ea306612e1ff6f60e2885ef48 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:37:52 +0530 Subject: [PATCH 1/5] Add error handling for `commands.NoPrivateMessage` --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index a739f6d..bccf00e 100644 --- a/main.py +++ b/main.py @@ -267,6 +267,7 @@ async def on_application_command_error(ctx: ApplicationContext, error: discord.D elif isinstance(error, commands.BadArgument): await ctx.respond(":x: Invalid argument.", ephemeral=True) elif isinstance(error, commands.BotMissingPermissions): await ctx.respond(":x: I don\'t have the required permissions to use this.\nIf you think this is a mistake, please go to server settings and fix isobot's role permissions.") elif isinstance(error, commands.BadBoolArgument): await ctx.respond(":x: Invalid true/false argument.", ephemeral=True) + elif isinstance(error, commands.NoPrivateMessage): await ctx.respond(":x: You can only use this command in a server!", ephemeral=True) else: logger.error(f"Command failure: An uncaught error occured while running the command.\n >>> {error}", module="main/Client") await ctx.respond(f"An uncaught error occured while running the command. (don't worry, developers will fix this soon)\n```\n{error}\n```") From a2511ec9d6f16a1d055953150a9a7b495cb8fd83 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sun, 28 Apr 2024 11:38:41 +0530 Subject: [PATCH 2/5] Add `/serverinfo` command to provide detailed information about a specific server --- cogs/utils.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/cogs/utils.py b/cogs/utils.py index d21c96f..4449715 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -318,6 +318,46 @@ async def nuke(self, ctx: ApplicationContext, channel: discord.TextChannel): await new_channel.send(f"Channel nuked by **{ctx.author.name}**!") await ctx.respond(embed=localembed, ephemeral=True) + @commands.slash_command( + name="serverinfo", + description="Get detailed information about the server." + ) + @commands.guild_only() + async def serverinfo(self, ctx: ApplicationContext): + """Get detailed information about the server.""" + localembed = discord.Embed( + title=f"Server info on **{ctx.guild.name}**", + description=f"*{ctx.guild.description}*" if ctx.guild.description is not None else '', + color=discord.Color.random() + ) + localembed.set_thumbnail(url=ctx.guild.icon) + localembed.set_footer(text=f"Server ID: {ctx.guild.id}") + if ctx.guild.banner is not None: + localembed.set_image(url=ctx.guild.banner) + + # Server Info Fields + localembed.add_field(name="Server Created On", value=ctx.guild.created_at.strftime("%b %d, %Y, %T")) + localembed.add_field(name="Member Count", value=f"{ctx.guild.member_count} members") + localembed.add_field(name="Server Owner", value=f"<@!{ctx.guild.owner_id}>") + localembed.add_field( + name="Total Number of Channels", + value=f"{len(ctx.guild.channels)-len(ctx.guild.categories)} channels\n({len(ctx.guild.text_channels)} Text | {len(ctx.guild.voice_channels)} Voice | {len(ctx.guild.forum_channels)} Forums)", + inline=True + ) + localembed.add_field(name="Total Number of Roles", value=f"{len(ctx.guild.roles)-1} roles") + localembed.add_field(name="Currently Active Threads", value=f"{len(await ctx.guild.active_threads())} threads") + localembed.add_field( + name="Active Invite Links", + value=f"{len(await ctx.guild.invites())} links {'(invites disabled)' if ctx.guild.invites_disabled else ''}" + ) + localembed.add_field(name="Server Verification Level", value=ctx.guild.verification_level, inline=True) + localembed.add_field( + name="Custom Expressions (emojis/stickers)", + value=f"{len(await ctx.guild.fetch_emojis())} emojis | {len(await ctx.guild.fetch_stickers())} stickers" + ) + + await ctx.respond(embed=localembed) + commandmanager = SlashCommandGroup("commandmanager", "Manage isobot's command registry.") @commandmanager.command( From af6683247d8f8f83093b23b37d09f1d507b07d87 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:09:25 +0530 Subject: [PATCH 3/5] Display thread channel names if total active threads is under 4 --- cogs/utils.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cogs/utils.py b/cogs/utils.py index 4449715..223d7b4 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -345,7 +345,16 @@ async def serverinfo(self, ctx: ApplicationContext): inline=True ) localembed.add_field(name="Total Number of Roles", value=f"{len(ctx.guild.roles)-1} roles") - localembed.add_field(name="Currently Active Threads", value=f"{len(await ctx.guild.active_threads())} threads") + threads = await ctx.guild.active_threads() + threads_display_list = str() + if len(threads) <= 4: # Display threads if total threads count is under 5 + for thread in threads: + threads_display_list += f"<#{thread.id}>, " + threads_display_list = threads_display_list.rstrip(", ") # Removing the final "," from the string + localembed.add_field( + name="Currently Active Threads", + value=f"{len(await ctx.guild.active_threads())} threads {f'({threads_display_list})' if threads_display_list != '' else ''}" + ) localembed.add_field( name="Active Invite Links", value=f"{len(await ctx.guild.invites())} links {'(invites disabled)' if ctx.guild.invites_disabled else ''}" From 2889f584cc12aaf14bb2b17ffc452fff735814f2 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:11:50 +0530 Subject: [PATCH 4/5] Remove an extra linebreak --- cogs/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/cogs/utils.py b/cogs/utils.py index 223d7b4..5d4a5a6 100644 --- a/cogs/utils.py +++ b/cogs/utils.py @@ -364,7 +364,6 @@ async def serverinfo(self, ctx: ApplicationContext): name="Custom Expressions (emojis/stickers)", value=f"{len(await ctx.guild.fetch_emojis())} emojis | {len(await ctx.guild.fetch_stickers())} stickers" ) - await ctx.respond(embed=localembed) commandmanager = SlashCommandGroup("commandmanager", "Manage isobot's command registry.") From bae582a6a3f94bd69d972b438f0c21526e20f9c3 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Sun, 28 Apr 2024 12:12:05 +0530 Subject: [PATCH 5/5] Add `/serverinfo` to commands registry --- config/commands.json | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/config/commands.json b/config/commands.json index 8e08a38..dafcaa2 100644 --- a/config/commands.json +++ b/config/commands.json @@ -838,5 +838,15 @@ "usable_by": "server admins", "disabled": false, "bugged": false - } + }, + "serverinfo": { + "name": "Server Info", + "description": "Get detailed information about the server.", + "type": "general utilities", + "cooldown": null, + "args": null, + "usable_by": "everyone", + "disabled": false, + "bugged": false + } }