# DC bot Part2 & 線上託管 & Cogs
## 點名 & 記得交社費

---
# Replit
https://replit.com/
註冊帳號
### Ceate Repl

### Add Secret


>按add secret
>

>加這幾行導入secret內容
### 最後應該長這樣

### 按Run執行,bot上線

---
# 線上託管
## keep alive
下載相關檔案 :
https://drive.google.com/drive/folders/1XhSlW9mJCFuAedfgPx53Uwf8nYHAgV9p
### 把keep_alive.py上傳到repl裡

### 加入下面的程式碼
```python=
import keep_alive
keep_alive.keep_alive()
```

## UptimeRobot
>bot監視器
https://uptimerobot.com/
註冊帳號
### add new monitor


### url取得


### 然後記得回去按Run
---
# Cogs
> 把你的功能模組化
### 類別(class)
>物件導向(OOP)
其實就是分門別類
以"學校"為例
其實我們創建的是名稱是"學校"的物件(定義何為"學校")
用法:
```python=
class school:
#constructor
def __init__(self, student):
#attribute
self.table=10
self.chair=5
self.student=student
#method
def good_morning(self):
print("Hello!!!")
#method
def student_num(self):
print(self.student)
```
```python=
TCFSH = school(1000)
TCGS = school(2000)
print(TCFSH.table) #10
print(TCGS.table) #10
print(TCFSH.student) #1000
print(TCGS.student) #2000
TCFSH.student_num() #1000
TCFSH.good_morning() #"Hello!!!"
```
### 寫法
main.py :
```python=
for fn in os.listdir("cogs"):
if fn.endswith(".py"):
bot.load_extension(f"cogs.{fn[:-3]}")
@bot.event
async def on_ready():
print(f"目前登入身份 --> {bot.user}")
channel=bot.get_channel(int(os.environ['contest_channel']))
await bot.change_presence(status=nextcord.Status.online, activity=ectivity)
@bot.command()
async def load(ctx,extension):
bot.load_extension(f"cogs.{extension}")
await ctx.send("loaded cog!")
@bot.command()
async def unload(ctx,extension):
bot.unload_extension(f"cogs.{extension}")
await ctx.send("unloaded cog!")
@bot.command()
async def reload(ctx,extension):
bot.reload_extension(f"cogs.{extension}")
await ctx.send("reloaded cog!")
```
func.py :
```python=
import nextcord
from nextcord.ext import commands
class func(commands.Cog):
def __init__(self,bot):
self.bot = bot
self.number = 10
@commands.command()
async def my_func(self, ctx):
await ctx.send("嗨嗨")
def setup(bot):
bot.add_cog(roles(bot))
```
### cogs資料夾
記得新增一個cogs資料夾
把所有cog檔案都放進去(main.py和keep_alive.py不用放)
## 沒了