Slash command checks

Introduction

This section contains documentation of decorator-based checks that dislash.py has.

Here’s a possible use case:

import dislash
from discord.ext import commands

bot = commands.Bot(command_prefix="!")
inter_client = dislash.InteractionClient(bot)

@inter_client.slash_command(description="A command for admins")
@dislash.has_permissions(administrator=True)
async def hello(inter):
    await inter.reply("Hello, administrator!")

bot.run("BOT_TOKEN")

If you want to respond with something like “You’re missing permissions!”, you should add an error handler using on_slash_command_error(inter, error) event, learn more about it here: on_slash_command_error

Checks

dislash.check(predicate)

A function that converts predicate(interaction) functions into application command decorators

Example

def is_guild_owner():
    def predicate(inter):
        return inter.author.id == inter.guild.owner_id
    return check(predicate)

@is_guild_owner()
@slash.command(description="Says Hello if you own the guild")
async def hello(inter):
    await inter.reply("Hello, Mr.Owner!")
dislash.check_any(*checks)

Similar to commands.check_any

dislash.cooldown(rate, per, type=<BucketType.default: 0>)

A decorator that adds a cooldown to a slash-command. Similar to discord.py cooldown decorator.

A cooldown allows a command to only be used a specific amount of times in a specific time frame. These cooldowns can be based either on a per-guild, per-channel, per-user, per-role or global basis. Denoted by the third argument of type which must be of enum type BucketType.

If a cooldown is triggered, then CommandOnCooldown is triggered in on_slash_command_error in the local error handler.

A command can only have a single cooldown.

Parameters
  • rate (int) – The number of times a command can be used before triggering a cooldown.

  • per (float) – The amount of seconds to wait for a cooldown when it’s been triggered.

  • type (BucketType) – The type of cooldown to have.

dislash.has_role(item)

Similar to commands.has_role

dislash.has_any_role(*items)

Similar to commands.has_any_role

dislash.has_permissions(**perms)

Similar to commands.has_permissions

dislash.has_guild_permissions(**perms)

Similar to commands.has_guild_permissions

dislash.dm_only()

Similar to commands.dm_only

dislash.guild_only()

Similar to commands.guild_only

dislash.is_owner()

Similar to commands.is_owner

dislash.is_nsfw()

Similar to commands.is_nsfw

dislash.bot_has_role(item)

Similar to commands.bot_has_role

dislash.bot_has_any_role(*items)

Similar to commands.bot_has_any_role

dislash.bot_has_permissions(**perms)

Similar to commands.bot_has_permissions

dislash.bot_has_guild_permissions(**perms)

Similar to commands.bot_has_guild_permissions