Slash util - A simple script to add application command support to discord.py v2.0

Overview

slash_util is a simple wrapper around slash commands for discord.py

This is written by an official discord.py helper to try and stop people using third party forks or otherwise. If any help is required, please ping Maya#9000 in one of the help channels. To any other helpers reading this, this script is exempt from rule 14.

Table of contents

Installation

BEFORE ANYTHING You must install discord.py 2.0 from GitHub:

pip install -U git+https://github.com/Rapptz/discord.py

This script will NOT work without it. See this message for more information on discord.py 2.0

  1. Go to the slash_util.py file

  2. Click the following button img

  3. Copy the entire text and paste it into your own file, then proceed to import it into files you need.

Defining parameters

A few different parameter types can be specified in accordance with the discord api.

These parameters may only be used inside slash commands, not within context menu commands.

  • str for strings
  • int or Range[min, max] for ints (see Ranges for more information)
  • float or Range[min, max] for floats (see Ranges for more information)
  • bool for booleans
  • discord.User or discord.Member for members
  • discord.Role for roles

For defining channel parameters, they are documented in Channels

Ranges

Ranges are a way to specify minimum and maximum values for ints and floats. They can be defined inside a type hint, for example:

@slash_util.slash_command()
async def my_command(self, ctx, number: slash_util.Range[0, 10]):
  # `number` will only be an int within this range
  await ctx.send(f"Your number was {number}!", ephemeral=True)

If you specify a float in either parameter, the value will be a float.

Channels

Channels can be defined using discord.TextChannel, VoiceChannel or CategoryChannel. You can specify multiple channel types via typing.Union:

@slash_util.slash_command()
async def my_command(self, ctx, channel: typing.Union[discord.TextChannel, discord.VoiceChannel]):
  await ctx.send(f'{channel.mention} is not a category!', ephemeral=True)

Examples

slash_util defines a bot subclass to automatically handle posting updated commands to discords api. This isn't required but highly recommended to use.

class MyBot(slash_util.Bot):
    def __init__(self):
        super().__init__(command_prefix="!")  # command prefix only applies to message based commands

        self.load_extension("cogs.my_cog")  # important!
        
if __name__ == '__main__':
    MyBot().run("token")

Sample cog:

class MyCog(slash_util.ApplicationCog):
    @slash_util.slash_command()  # sample slash command
    async def slash(self, ctx: slash_util.Context, number: int):
        await ctx.send(f"You selected #{number}!", ephemeral=True)
    
    @slash_util.message_command(name="Quote")  # sample command for message context menus
    async def quote(self, ctx: slash_util.Context, message: discord.Message):  # these commands may only have a single Message parameter
        await ctx.send(f'> {message.clean_content}\n- {message.author}')
    
    @slash_util.user_command(name='Bonk')  # sample command for user context menus
    async def bonk(self, ctx: slash_util.Context, user: discord.Member):  # these commands may only have a single Member parameter
        await ctx.send(f'{ctx.author} BONKS {user} :hammer:')

def setup(bot):
    bot.add_cog(MyCog(bot))

See the api documentation below for more information on attributes, functions and more.

API Documentation

deco @slash_command(**kwargs)

Defines a function as a slash-type application command.

Parameters:

  • name: str
    • The display name of the command. If unspecified, will use the functions name.
  • guild_id: Optional[int]
    • The guild ID this command will belong to. If unspecified, the command will be uploaded globally.
  • description: str
    • The description of the command. If unspecified, will use the functions docstring, or "No description provided" otherwise.
deco @message_command(**kwargs)

Defines a function as a message-type application command.

Parameters:

  • name: str
    • The display name of the command. If unspecified, will use the functions name.
  • guild_id: Optional[int]
    • The guild ID this command will belong to. If unspecified, the command will be uploaded globally.
deco @user_command(**kwargs)

Defines a function as a user-type application command.

Parameters:

  • name: str
    • The display name of the command. If unspecified, will use the functions name.
  • guild_id: Optional[int]
    • The guild ID this command will belong to. If unspecified, the command will be uploaded globally.
deco @describe(**kwargs: str)

Sets the description for the specified parameters of the slash command. Sample usage:

@slash_util.slash_command()
@describe(channel="The channel to ping")
async def mention(self, ctx: slash_util.Context, channel: discord.TextChannel):
    await ctx.send(f'{channel.mention}')

If this decorator is not used, parameter descriptions will be set to "No description provided." instead.

class Range(min: NumT | None, max: NumT)

Defines a minimum and maximum value for float or int values. The minimum value is optional.

async def number(self, ctx, num: slash_util.Range[0, 10], other_num: slash_util.Range[10]):
    ...
class Bot(command_prefix, help_command=<default-help-command>, description=None, **options)

None

Methods:

get_application_command(self, name: str)

Gets and returns an application command by the given name.

Parameters:

  • name: str
    • The name of the command.

Returns:

  • Command
    • The relevant command object
  • None
    • No command by that name was found.

async delete_all_commands(self, guild_id: int | None = None)

Deletes all commands on the specified guild, or all global commands if no guild id was given.

Parameters:

  • guild_id: Optional[str]
    • The guild ID to delete from, or None to delete global commands.

async delete_command(self, id: int, guild_id: int | None = None)

Deletes a command with the specified ID. The ID is a snowflake, not the name of the command.

Parameters:

  • id: int
    • The ID of the command to delete.
  • guild_id: Optional[str]
    • The guild ID to delete from, or None to delete a global command.

async sync_commands(self)

Uploads all commands from cogs found and syncs them with discord. Global commands will take up to an hour to update. Guild specific commands will update immediately.

class Context(bot: BotT, command: Command[CogT], interaction: discord.Interaction)

The command interaction context.

Attributes

Methods:

async send(self, content=..., **kwargs)

Responds to the given interaction. If you have responded already, this will use the follow-up webhook instead. Parameters embed and embeds cannot be specified together. Parameters file and files cannot be specified together.

Parameters:

  • content: str
    • The content of the message to respond with
  • embed: discord.Embed
    • An embed to send with the message. Incompatible with embeds.
  • embeds: List[discord.Embed]
    • A list of embeds to send with the message. Incompatible with embed.
  • file: discord.File
    • A file to send with the message. Incompatible with files.
  • files: List[discord.File]
    • A list of files to send with the message. Incompatible with file.
  • ephemeral: bool
    • Whether the message should be ephemeral (only visible to the interaction user).
    • Note: This field is ignored if the interaction was deferred.

Returns

async def defer(self, *, ephemeral: bool = False) -> None:

Defers the given interaction.

This is done to acknowledge the interaction. A secondary action will need to be sent within 15 minutes through the follow-up webhook.

Parameters:

  • ephemeral: bool
    • Indicates whether the deferred message will eventually be ephemeral. Defaults to False

Returns

  • None

Raises

property cog(self)

The cog this command belongs to.

property guild(self)

The guild this interaction was executed in.

property message(self)

The message that executed this interaction.

property channel(self)

The channel the interaction was executed in.

property author(self)

The user that executed this interaction.

class ApplicationCog(*args: Any, **kwargs: Any)

The cog that must be used for application commands.

Attributes:

Owner
Maya
Maya
A multi exploit instagram exploitation framework

Instagram Exploitation Framework About IEF Is an open source Instagram Exploitation Framework with various Exploits that could be used to mod your pro

Instagram Exploitation Framework - BirdSecurity 1 May 23, 2022
Upbit(업비트) Cryptocurrency Exchange OPEN API Client for Python

Base Repository Python Upbit Client Repository Upbit OPEN API Client @Author: uJhin @GitHub: https://github.com/uJhin/upbit-client/ @Officia

Yu Jhin 37 Nov 06, 2022
Wordnik Python public library

Python 2.7 client for Wordnik.com API Overview This is a Python 2.7 client for the Wordnik.com v4 API. For more information, see http://developer.word

Wordnik 224 Dec 29, 2022
Pluggable Telethon - Telegram UserBot

A stable pluggable Telegram userbot, based on Telethon.

Team Ultroid 2.3k Dec 30, 2022
Simple progressbar for discord

⚙️ DiscordProgressbar 📂 Установка | Installation pip install discordbar 📚 Документация | Documentation 📞 Связаться со мной | Сontact with me 📜 Ли

DenyS 26 Nov 30, 2022
A reddit bot that imitates the popular reddit bot "u/repostsleuthbot" to trick people into clicking on a rickroll

Reddit-Rickroll-Bot A reddit bot that imitates the popular reddit bot "u/repostsleuthbot" to trick people into clicking on a rickroll Made with The Py

0 Jul 16, 2022
📷 An Instagram bot written in Python using Selenium on Google Chrome

📷 An Instagram bot written in Python using Selenium on Google Chrome. It will go through posts in hashtag(s) and like and comment on them.

anniedotexe 47 Dec 19, 2022
An EmbedBuilder in Python for discord.py embeds. Pip Module.

Discord.py-MaxEmbeds An EmbedBuilder for Discord bots in Python. You need discord.py to use this module. Installation Step 1 First you have to install

Max Tischberger 6 Jan 13, 2022
An interactive and multi-function Telegram bot, made especially for Telegram groups.

PyKorone An interaction and fun bot for Telegram groups, having some useful and other useless commands. Created as an experiment and learning bot but

Amano Team 17 Nov 12, 2022
trackbranch is a tool for developers that can be used to store collections of branches in the form of profiles.

trackbranch trackbranch is a tool for developers that can be used to store collections of branches in the form of profiles. This can be useful for sit

Kevin Morris 1 Oct 21, 2021
A telegram bot that sends a meme a day, from reddit's top meme of the day

MemeBot A telegram bot that sends a meme a day, from reddit's top meme of the day You can use the bot either with an external scheduler (ex: pythonany

Michele Vitulli 1 Dec 13, 2021
Trading Strategies (~50%) developed by GreenT on QuantConnect platform over the autumn quarter

Trading Strategies ~50% of codes from the Applied Financial Technology Course. Contributors: Claire W. Derrick T. Frank L. Utkarsh T. Course Leads: Dy

Utkarsh 2 Feb 07, 2022
A Bot For Streaming Videos In Tg Voice Chats.

「•ᴍɪsᴇʀʏ ᴠɪᴅᴇᴏ sᴛʀᴇᴀᴍᴇʀ•」 ᴀ ғɪɴᴇ & ғɪʀsᴛ ᴄʟᴀss ᴘʀᴏᴊᴇᴄᴛ ғᴏʀ ᴘʟᴀʏɪɴɢ ᴠɪᴅᴇᴏs ɪɴ ᴠᴏɪᴄᴇ ᴄʜᴀᴛ ʙʏ xᴇʙᴏʀɴ | •ᴘᴏᴡᴇʀᴇᴅ ʙʏ ᴛɢᴄᴀʟʟs and ᴘʏʀᴏ •ᴅᴇᴘʟᴏʏ ᴍɪsᴇʀʏ ᴛᴏ ʜᴇʀ

Turdus Maximus 22 Nov 12, 2022
Huggingface transformers for discord

disformers Huggingface transformers for discord base source butyr/huggingface-transformer-chatbots install pip install -U disformers example see examp

SpaceDEVofficial 1 Nov 09, 2021
Charged's cogs for Red!

Light-Cogs Charged's cogs for Red! Read below for more information. Features and Cogs TechInfo Lots of commands helping you and your devices! Extended

Charged 2 Jan 07, 2022
Retrieve information from DBLP and update BibTex files automatically

Rebib TLDR: This script retrieves information from DBLP to update your BibTex files. python rebib.py --bibfile xxx.bib It first parses the bib entries

Shangtong Zhang 49 Jan 01, 2023
Injector/automatic translator (using deepL API) for Tsukihime Remake

deepLuna Extractor/Editor/Translator/Injector for Tsukihime Remake About deepLuna, from "deepL", the machine translation service, and "Luna", the name

30 Dec 15, 2022
dex.guru python sdk

dexguru-sdk.py dexguru-sdk.py allows you to access dex.guru public methods from your async python scripts. Installation To install latest version, jus

DexGuru 17 Dec 06, 2022
Discord group chat leaver.

Discord group chat leaver I know many people who have fallen victim to these weird group chat spammers including me. I made this script to help those

cliphd 3 Feb 27, 2022
Discord Bot for SurPath Hub's server

Dayong Dayong is dedicated to helping Discord servers build and manage their communities. Multipurpose —lots of features, lots of automation. Self-hos

SurPath Hub 6 Dec 18, 2021