Skip to content

Commit 9e4007d

Browse files
committed
chore: update example
1 parent 4fbc67d commit 9e4007d

File tree

3 files changed

+21
-67
lines changed

3 files changed

+21
-67
lines changed

examples/bot.py

Lines changed: 9 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,16 @@
1-
from os import getenv
2-
31
import interactions
4-
from dotenv import load_dotenv
5-
from fastapi import WebSocket, WebSocketDisconnect
6-
from interactions.ext.fastapi import setup
7-
8-
load_dotenv()
9-
10-
bot = interactions.Client(getenv("TOKEN"), intents=interactions.Intents.ALL)
11-
api = setup(bot)
12-
13-
14-
@bot.event()
15-
async def on_start():
16-
print("bot started")
17-
18-
19-
@bot.command()
20-
async def test_command(ctx):
21-
await ctx.send("Ok")
22-
23-
24-
@api.route("get", "/")
25-
async def index():
26-
return {"test": "yay"}
2+
from interactions_restful import setup
3+
from interactions_restful.backends.fast_api import FastAPI
274

285

29-
@api.get("/guilds/{guild_id}/members/{member_id}")
30-
async def test(guild_id: int, member_id: int):
31-
for guild in bot.guilds:
32-
if int(guild.id) == guild_id:
33-
break
34-
member = await guild.get_member(member_id)
35-
return member._json
6+
client = interactions.Client()
7+
setup(client, FastAPI, "localhost", 8000)
8+
client.load_extension("exts.my_ext")
369

3710

38-
@api.websocket("/ws/")
39-
async def websocket_control(websocket: WebSocket):
40-
"""
41-
Before using you have to install additional requirement:
42-
`pip install uvicorn[standard]`
43-
"""
44-
await websocket.accept()
45-
await websocket.send_json({"test": "yayayyayayyaya"})
46-
try:
47-
while True:
48-
packet = await websocket.receive_json()
49-
print(packet)
50-
# some stuff with websocket
51-
except WebSocketDisconnect:
52-
pass
11+
@interactions.listen()
12+
async def on_startup():
13+
print(f"Bot `{client.user.username}` started up")
5314

5415

55-
bot.start()
16+
client.start("TOKEN")

examples/exts/cog.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/exts/my_ext.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from interactions import Extension, slash_command
2+
from interactions_restful import route
3+
4+
5+
class MyExtension(Extension):
6+
@route("GET", "/")
7+
async def index(self):
8+
return {"data": "hello interactions.py"}
9+
10+
@slash_command()
11+
async def command(self, ctx):
12+
await ctx.send("hello, api!")

0 commit comments

Comments
 (0)