CommandSet - LeConstellationniste/Discord.py-Framework- GitHub Wiki

CommandSet & Help Command

Class CommandSet

Base class to create a group of commands and listeners. Example :

import asyncio
import discord
from discordEasy.objects import CommandSet, command, listener

class MyCommandSet(CommandSet):
	def __init__(self):
		super().__init__()
    self.description = "A example of CommandSet"

	@command(name="HelloWorld", aliases=("Hello", ))
	async def my_command(self, message):
		await message.channel.send("Hello world !")

	@listener()
	async def on_member_join(self, member):
		await member.send(f"Welcome in {member.guild.name} !")

Attributes

Attributes Name Type Description Default value
commands listCommand(/LeConstellationniste/Discord.py-Framework-/wiki/Command][Command) The list of commands of CommandSet (automatically initialized) []
listeners listListener(/LeConstellationniste/Discord.py-Framework-/wiki/Listener][Listener) The list of listeners of CommandSet (automatically initialized) []
description str The description for the CommandSet. Use in the help default command ""
name str The name of CommandSet. By default the name of the class. cls.__name__

Methods

  • CommandSet.execute_cmd

    • Description: A routine wich check all commands of CommandSet.commands with the command name pass in argument and execute the command if the name is valid.

    • Arguments:

      • message: discord.Message - The Discord Message which call a command.
      • name: str - The command name use in Discord Message.
      • options: list[str] - The list of options to pass in the command function.
  • CommandSet.execute_listener

    • Description: A routine wich check all listeners of CommandSet.listeners with the event name pass in argument and execute the listener if the event name is valid.

    • Arguments:

      • event_name: str - The event name call.
      • *args: list - The list of arguments to pass in the listener function.

BaseHelp

A base class for help command, this class is used also for the default help command. This class is a subclass of CommandSet and has the same attributes and methods.

Attributes

With attributes of CommandSet:

Attributes Name Type Description Default value
description str The description for the CommandSet. Use in the help default command "The help commands to learn how to use the bot."
name str The name of CommandSet. By default the name of the class. "Commands Help"
bot Bot A instance of Bot which has this CommandSet.

Methods

  • base_embed

  • first_page

  • Description: A method which create the first embed for the help command.

  • Arguments:

    • OPTIONNAL[author]: discord.User - The user who called up the command.
  • Return: discord.Embed

  • command_pages

    • Description: A method which create the embeds for a list of commands or a CommandSet instance.

    • Arguments:

      • set_commands: listCommand(/LeConstellationniste/Discord.py-Framework-/wiki/Command][Command) or CommandSet - The list of commands or the CommandSet for which the help embeds must be created.
    • OPTIONNAL[author]: discord.User - The user who called up the command.

    • Return: listdiscord.Embed(/LeConstellationniste/Discord.py-Framework-/wiki/discord.Embed][Embed)

  • help

    • Description: A routine decorate with the function command. It's the default help command.
  • staticmethod setup

    • Description: A staticmethod to add the CommandSet to the bot.

    • Arguments:

      • bot: Bot - The bot to which the CommandSet is added.