Auto defer
attrs
class
AutoDefer
¶
Automatically defer application commands for you!
Attr attributes:
Name | Type | Description |
---|---|---|
enabled |
bool |
Whether or not auto-defer is enabled |
ephemeral |
bool |
Should the command be deferred as ephemeral or not |
time_until_defer |
float |
How long to wait before automatically deferring |
Source code in naff/models/naff/auto_defer.py
@define()
class AutoDefer:
"""Automatically defer application commands for you!"""
enabled: bool = field(default=False)
"""Whether or not auto-defer is enabled"""
ephemeral: bool = field(default=False)
"""Should the command be deferred as ephemeral or not"""
time_until_defer: float = field(default=1.5)
"""How long to wait before automatically deferring"""
async def __call__(self, ctx: "InteractionContext") -> None:
if self.enabled:
if self.time_until_defer > 0:
loop = asyncio.get_event_loop()
loop.call_later(self.time_until_defer, loop.create_task, self.defer(ctx))
else:
await ctx.defer(self.ephemeral)
async def defer(self, ctx: "InteractionContext") -> None:
"""Defer the command"""
if not ctx.responded or not ctx.deferred:
try:
await ctx.defer(self.ephemeral)
except (AlreadyDeferred, NotFound, BadRequest, HTTPException):
pass
async
method
defer(self, ctx)
¶
Defer the command
Source code in naff/models/naff/auto_defer.py
async def defer(self, ctx: "InteractionContext") -> None:
"""Defer the command"""
if not ctx.responded or not ctx.deferred:
try:
await ctx.defer(self.ephemeral)
except (AlreadyDeferred, NotFound, BadRequest, HTTPException):
pass