-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommand_example.py
More file actions
29 lines (23 loc) · 865 Bytes
/
Copy pathcommand_example.py
File metadata and controls
29 lines (23 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import asyncio
from astra import Client, Filters
from astra.errors import MessageSendError
async def main():
# Example using commands, editing messages and handling errors
async with Client(session_id="command_example") as client:
@client.on_message(Filters.command(".ping"))
async def ping(msg):
import time
start = time.monotonic()
# Send a placeholder and edit it with the result
temp = await msg.respond("...")
latency = (time.monotonic() - start) * 1000
await client.chat.edit_message(temp.id, f"Latency: {latency:.0f}ms")
@client.on_message(Filters.command(".me"))
async def me(msg):
# Get current account info
me = await client.get_me()
await msg.reply(f"Name: {me.name}\nID: {me.id.serialized}")
print("Command example running...")
await client.run_forever()
if __name__ == "__main__":
asyncio.run(main())