-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathchannel_example.py
45 lines (30 loc) · 1.22 KB
/
channel_example.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os # noqa
import sys # noqa
import inspect # noqa
currentdir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe()))
) # noqa
parentdir = os.path.dirname(currentdir) # noqa
sys.path.insert(0, parentdir) # noqa
from dotenv import load_dotenv
env_file = os.path.join(os.path.dirname(__file__), "..", "..", ".env") # noqa
load_dotenv(env_file) # noqa
from swibots import BotApp, BotContext, ChannelCreatedEvent, Message
from swibots.bots.filters import channel
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
env_file = os.path.join(os.path.dirname(__file__), "..", "..", ".env")
load_dotenv(env_file)
TOKEN = os.getenv("TOKEN")
app = BotApp(TOKEN, "your bot description")
@app.on_channel_created(channel("d71e33f9-8e12-491f-b041-d02ea6ec6520"))
async def channel_created_handler(ctx: BotContext[ChannelCreatedEvent]):
new_channel_name = ctx.event.channel.name
new_channel_id = ctx.event.channel.id
m = Message()
m.message = f"Channel {new_channel_name} created with id {new_channel_id}"
m.community_id = ctx.event.community.id
m.channel_id = "d71e33f9-8e12-491f-b041-d02ea6ec6520"
await ctx.send_message(message=m)
app.run()