mirror of
https://gitlab.com/pancakes1234/wdiscordbotserver.git
synced 2025-06-16 07:14:21 -06:00
Refactor APICheck cog to use app_commands for API status checks
This commit is contained in:
parent
cce4685a29
commit
92c63cee2c
@ -1,6 +1,8 @@
|
||||
import discord
|
||||
from discord.ext import commands, tasks
|
||||
import aiohttp
|
||||
from discord import app_commands
|
||||
import asyncio
|
||||
|
||||
class APICheck(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
@ -17,19 +19,21 @@ class APICheck(commands.Cog):
|
||||
return url, resp.status == 200
|
||||
except Exception:
|
||||
return url, False
|
||||
@app_commands.command(name="apicheck", description="Check the status of APIs.")
|
||||
async def apicheck(self, interaction: discord.Interaction):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
results = await asyncio.gather(
|
||||
*(self.check_url(session, url) for url in self.urls)
|
||||
)
|
||||
|
||||
@commands.command(name="apicheck")
|
||||
async def apicheck(self, ctx):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
results = await asyncio.gather(
|
||||
*(self.check_url(session, url) for url in self.urls)
|
||||
)
|
||||
embed = discord.Embed(title="API Status Check", color=discord.Color.blue())
|
||||
for url, status in results:
|
||||
status_str = "🟢 Online" if status else "🔴 Offline"
|
||||
embed.add_field(name=url, value=status_str, inline=False)
|
||||
await interaction.response.send_message(embed=embed)
|
||||
|
||||
embed = discord.Embed(title="API Status Check", color=discord.Color.blue())
|
||||
for url, status in results:
|
||||
status_str = "🟢 Online" if status else "🔴 Offline"
|
||||
embed.add_field(name=url, value=status_str, inline=False)
|
||||
await ctx.send(embed=embed)
|
||||
async def cog_load(self):
|
||||
self.bot.tree.add_command(self.apicheck)
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(APICheck(bot))
|
||||
async def setup(bot):
|
||||
await bot.add_cog(APICheck(bot))
|
Loading…
x
Reference in New Issue
Block a user