Ruby-Cogs/appeals/common/checks.py
Valerie 477974d53c
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
Upload 2 Cogs & Update README
2025-05-23 01:30:53 -04:00

23 lines
616 B
Python

from discord.ext.commands.core import check
from redbot.core import commands
def ensure_db_connection():
"""Decorator to ensure a database connection is active.
Example:
```python
@ensure_db_connection()
@commands.command()
async def mycommand(self, ctx):
await ctx.send("Database connection is active")
```
"""
async def predicate(ctx: commands.Context) -> bool:
if not ctx.cog.db:
txt = "Database connection is not active, try again later"
raise commands.UserFeedbackCheckFailure(txt)
return True
return check(predicate)