Skip to content

Commit 724f56f

Browse files
authored
Merge pull request #381 from PyBotDevs/add-serverinfo-cmd
Add `/serverinfo` command to provide detailed information about a specific server
2 parents 0b636c8 + bae582a commit 724f56f

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

cogs/utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,54 @@ async def nuke(self, ctx: ApplicationContext, channel: discord.TextChannel):
318318
await new_channel.send(f"Channel nuked by **{ctx.author.name}**!")
319319
await ctx.respond(embed=localembed, ephemeral=True)
320320

321+
@commands.slash_command(
322+
name="serverinfo",
323+
description="Get detailed information about the server."
324+
)
325+
@commands.guild_only()
326+
async def serverinfo(self, ctx: ApplicationContext):
327+
"""Get detailed information about the server."""
328+
localembed = discord.Embed(
329+
title=f"Server info on **{ctx.guild.name}**",
330+
description=f"*{ctx.guild.description}*" if ctx.guild.description is not None else '',
331+
color=discord.Color.random()
332+
)
333+
localembed.set_thumbnail(url=ctx.guild.icon)
334+
localembed.set_footer(text=f"Server ID: {ctx.guild.id}")
335+
if ctx.guild.banner is not None:
336+
localembed.set_image(url=ctx.guild.banner)
337+
338+
# Server Info Fields
339+
localembed.add_field(name="Server Created On", value=ctx.guild.created_at.strftime("%b %d, %Y, %T"))
340+
localembed.add_field(name="Member Count", value=f"{ctx.guild.member_count} members")
341+
localembed.add_field(name="Server Owner", value=f"<@!{ctx.guild.owner_id}>")
342+
localembed.add_field(
343+
name="Total Number of Channels",
344+
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)",
345+
inline=True
346+
)
347+
localembed.add_field(name="Total Number of Roles", value=f"{len(ctx.guild.roles)-1} roles")
348+
threads = await ctx.guild.active_threads()
349+
threads_display_list = str()
350+
if len(threads) <= 4: # Display threads if total threads count is under 5
351+
for thread in threads:
352+
threads_display_list += f"<#{thread.id}>, "
353+
threads_display_list = threads_display_list.rstrip(", ") # Removing the final "," from the string
354+
localembed.add_field(
355+
name="Currently Active Threads",
356+
value=f"{len(await ctx.guild.active_threads())} threads {f'({threads_display_list})' if threads_display_list != '' else ''}"
357+
)
358+
localembed.add_field(
359+
name="Active Invite Links",
360+
value=f"{len(await ctx.guild.invites())} links {'(invites disabled)' if ctx.guild.invites_disabled else ''}"
361+
)
362+
localembed.add_field(name="Server Verification Level", value=ctx.guild.verification_level, inline=True)
363+
localembed.add_field(
364+
name="Custom Expressions (emojis/stickers)",
365+
value=f"{len(await ctx.guild.fetch_emojis())} emojis | {len(await ctx.guild.fetch_stickers())} stickers"
366+
)
367+
await ctx.respond(embed=localembed)
368+
321369
commandmanager = SlashCommandGroup("commandmanager", "Manage isobot's command registry.")
322370

323371
@commandmanager.command(

config/commands.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,5 +838,15 @@
838838
"usable_by": "server admins",
839839
"disabled": false,
840840
"bugged": false
841-
}
841+
},
842+
"serverinfo": {
843+
"name": "Server Info",
844+
"description": "Get detailed information about the server.",
845+
"type": "general utilities",
846+
"cooldown": null,
847+
"args": null,
848+
"usable_by": "everyone",
849+
"disabled": false,
850+
"bugged": false
851+
}
842852
}

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ async def on_application_command_error(ctx: ApplicationContext, error: discord.D
267267
elif isinstance(error, commands.BadArgument): await ctx.respond(":x: Invalid argument.", ephemeral=True)
268268
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.")
269269
elif isinstance(error, commands.BadBoolArgument): await ctx.respond(":x: Invalid true/false argument.", ephemeral=True)
270+
elif isinstance(error, commands.NoPrivateMessage): await ctx.respond(":x: You can only use this command in a server!", ephemeral=True)
270271
else:
271272
logger.error(f"Command failure: An uncaught error occured while running the command.\n >>> {error}", module="main/Client")
272273
await ctx.respond(f"An uncaught error occured while running the command. (don't worry, developers will fix this soon)\n```\n{error}\n```")

0 commit comments

Comments
 (0)