-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (44 loc) · 1.38 KB
/
Copy pathmain.py
File metadata and controls
56 lines (44 loc) · 1.38 KB
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
46
47
48
49
50
51
52
53
54
55
56
import os
import dotenv
import discord
from discord.ext import commands
import traceback
import asyncio
import signal
import requests
dotenv.load_dotenv()
TOKEN = os.getenv("TOKEN")
PREFIX = os.getenv("PREFIX")
EXTENSIONS = [
"cogs.timetable"]
def handler(signum, frame):
print('signal catched')
URL = "https://discord.com/api/channels/706779308211044352/messages"
headers = {
"Authorization": f"Bot {TOKEN}"}
item = {"content": "こんにちは"}
requests.post(URL, headers=headers, json=item)
signal.signal(signal.SIGTERM, handler)
class Catalk(commands.Bot):
def __init__(self, command_prefix):
super().__init__(command_prefix)
for cog in EXTENSIONS:
try:
self.load_extension(cog)
print(f"Loaded Extension {cog}.py.")
except Exception:
traceback.print_exc()
async def on_ready(self):
print(f"Bot is ready! \nlibrary version:{discord.__version__}")
channel = bot.get_channel(706779308211044352)
await channel.send(f"{self.user}: 起動完了")
if __name__ == '__main__':
bot = Catalk(command_prefix=PREFIX)
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(bot.start(TOKEN))
except KeyboardInterrupt:
loop.run_until_complete(bot.logout())
# cancel all tasks lingering
finally:
loop.close()