Command Decorator
from main import server_details
Command Decorator
The command decorator is used to mark a coroutine as a command listener. Usage:
@Command(server_details)
async def hi(command: ChatCommand):
print("Command Ran!")The fact that the coroutine's name is hi means that the command will be <prefix>hi .
You also get access to this ChatCommand object which has a slew of useful information about the how the command was called.
sender_name
The name of the person that called the command, e.g. olijeffers0n
sender_steamid
The steamID of the person that called the command
time
The time that the command was called, as a CommandTime object. This wraps a datetime object, and the raw UNIX Epoch time
command
The name of the command that was called, e.g. hi
args
A list of strings that was passed as arguments to the command. E.g. - !hi one two three would result in args being ["one", "two, "three"]
This decorator returns a RegisteredListener instance
Aliases
You don't want to have to register 100's of commands for every permutation of phrasing, so why should you!
@ChatCommand(server_details, aliases=["hello", "hey"])
async def hi(command: ChatCommand):
print("Command Ran!")This is a simple example of how you could incorporate different function names into one command, but sometimes we need more than that!
This will allow you to check ANY string as it is passed in and perform checking on it. You just have to provide a callable, so a lambda or function reference will work! It will provide the current command as an argument and you can perform any logic you need!
Last updated
Was this helpful?