-
Notifications
You must be signed in to change notification settings - Fork 40
/
ex04.py
31 lines (23 loc) · 991 Bytes
/
ex04.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
import json
from khl import Bot, Message
# load config from config/config.json, replace `path` to your own config file
# config template: `./config/config.json.example`
with open('../config/config.json', 'r', encoding='utf-8') as f:
config = json.load(f)
# init Bot
bot = Bot(token=config['token'])
# register command
# invoke this via saying `!hello` in channel
@bot.command(name='hello')
async def world(msg: Message):
# quote reply
await msg.reply('world for you!')
# msg from reply_temp & send_temp will be cleaned when you restart client or refresh browser
await msg.reply('world only for you!', is_temp=True)
# send to current channel
await msg.ctx.channel.send('world for all!')
# send to current channel, but only visible to `msg.author`
# same as `msg.reply_temp()`, but can set `temp_target_id` explicitly
await msg.ctx.channel.send('world only for you too!', temp_target_id=msg.author.id)
# everything done, go ahead now!
bot.run()