Context¶
For each command invoked, the first argument is always a Context
instance, which holds a lot of
metadata, and a few utility functions to help you write commands.
A lot of the time, these are the three main attributes you'll be using:
Context.room
(nio.MatrixRoom
) - the room the command was invoked in.Context.event
(nio.RoomMessageText
) - the message that invoked this command.Context.respond
- a utility class to help you respond to the command.
Command Context¶
Event-based context for a command callback
original_response
property
¶
original_response: Optional[RoomSendResponse]
The result of Context.reply(), if it exists.
respond
async
¶
respond(
content: Optional[str] = None,
file: Optional[BaseAttachment] = None,
) -> ContextualResponse
Responds to the current event.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
Optional[str]
|
The text to reply with |
None
|
file |
Optional[BaseAttachment]
|
A file to reply with |
None
|
Returns:
Type | Description |
---|---|
ContextualResponse
|
|
Contextual Response¶
Context class for managing replies.
Usage of this function is not required, however it is a useful utility.
reply
async
¶
reply(*args) -> ContextualResponse
Replies to the current response.
This does NOT reply to the original invoking message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
args to pass to send_message |
()
|
Returns:
Type | Description |
---|---|
ContextualResponse
|
a new ContextualResponse object. |
edit
async
¶
edit(content: str, **kwargs) -> ContextualResponse
Edits the current response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
str
|
The new content to edit with |
required |
kwargs |
Any extra arguments to pass to Client.edit_message |
{}
|
Returns:
Type | Description |
---|---|
ContextualResponse
|
self |