Skip to content

Commit 797e10a

Browse files
fix: add bot join date to server stats output in markdown and HTML formats
1 parent 47fbf1b commit 797e10a

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

bot_cmds.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,25 @@ async def server_stats(self, ctx):
242242
try:
243243
# Create a markdown string for the file content
244244
response = "# Current Servers\n\n"
245-
response += "| Name | ID | Shard ID | Member Count | Channels |\n"
246-
response += "|----------------------|-----------------|----------|--------------|---------------|\n"
245+
response += "| Name | ID | Shard ID | Member Count | Bot Join Date | Channels |\n"
246+
response += "|----------------------|-----------------|----------|--------------|----------------------|---------------|\n"
247247

248248
# Iterate through each guild and add its details to the response
249249
for guild in self.bot.guilds:
250250
channels = ", ".join(channel.name for channel in guild.channels)
251-
response += f"| {guild.name} | {guild.id} | {guild.shard_id or 'N/A'} | {guild.member_count} | {channels} |\n"
251+
# Try to get the bot's join date for this guild (guild.me.joined_at)
252+
try:
253+
bot_member = getattr(guild, "me", None)
254+
join_dt = getattr(bot_member, "joined_at", None)
255+
if join_dt:
256+
# Format as ISO for clarity
257+
bot_join = join_dt.isoformat()
258+
else:
259+
bot_join = "Unknown"
260+
except Exception:
261+
bot_join = "Unknown"
262+
263+
response += f"| {guild.name} | {guild.id} | {guild.shard_id or 'N/A'} | {guild.member_count} | {bot_join} | {channels} |\n"
252264

253265
# Create a markdown file in memory
254266
markdown_file = io.BytesIO(response.encode("utf-8"))
@@ -262,8 +274,18 @@ async def server_stats(self, ctx):
262274
shard = guild.shard_id or "N/A"
263275
members = guild.member_count
264276
channels_esc = html.escape(channels)
277+
# Bot join date (if available)
278+
try:
279+
bot_member = getattr(guild, "me", None)
280+
join_dt = getattr(bot_member, "joined_at", None)
281+
bot_join = (
282+
html.escape(join_dt.isoformat()) if join_dt else "Unknown"
283+
)
284+
except Exception:
285+
bot_join = "Unknown"
286+
265287
html_rows.append(
266-
f"<tr><td>{name}</td><td>{guild.id}</td><td>{shard}</td><td>{members}</td><td>{channels_esc}</td></tr>"
288+
f"<tr><td>{name}</td><td>{guild.id}</td><td>{shard}</td><td>{members}</td><td>{bot_join}</td><td>{channels_esc}</td></tr>"
267289
)
268290

269291
html_content = (
@@ -278,7 +300,7 @@ async def server_stats(self, ctx):
278300
"<body>\n"
279301
"<h1>OpenGLaDOS — Current Servers</h1>\n"
280302
"<table>\n"
281-
"<thead><tr><th>Name</th><th>ID</th><th>Shard ID</th><th>Member Count</th><th>Channels</th></tr></thead>\n"
303+
"<thead><tr><th>Name</th><th>ID</th><th>Shard ID</th><th>Member Count</th><th>Bot Join Date</th><th>Channels</th></tr></thead>\n"
282304
"<tbody>"
283305
+ "\n".join(html_rows)
284306
+ "</tbody>\n</table>\n<footer><p>Generated by OpenGLaDOS Bot</p></footer>\n</body>\n</html>"

0 commit comments

Comments
 (0)