Voxel-Fox-Ltd/Novus

[FEATURE REQUEST] `vbu.checks.is_slash_command()`

Closed this issue · 3 comments

vbu.checks.is_slash_command() would raise :exc:IsNotSlashCommand(CommandError) if the command is not used as a slash command.

I made my own implementation earlier, thought I'd post it here.

import typing

from discord.ext import commands


class IsNotSlashCommand(commands.CheckFailure):
    """
    The generic error for the bot failing the :func:`utils.checks.is_slash_command` check.
    """


def is_slash_command():
    """
    The check for whether or not the command is being used in a slash command (as defined by `ctx` being an instance of :class:`discord.ext.commands.SlashContext`).

    Raises:
        `IsNotSlashCommand`: If the command isn't being used in a slash command.
    """

    async def predicate(ctx: typing.Union[commands.Context, commands.SlashContext]):
        if isinstance(ctx.bot, commands.SlashContext):
            return True
        raise IsNotSlashCommand()
    return commands.check(predicate)

I definitely have written these checks myself before because I removed them from VBU to move to Novus, but I can't find them in the docs 🤔

Closed with 8d30463.