# 10/9 Discord Bot 開發(二)
:::info
時間:2023/10/09 GMT+8 22:30 ~ 23:30
地點:-
參與:xiaojie4082

:::
## 套件庫變更
:::warning
因 discord.py 不支援 Application Commands,為使用應用程式命令,改安裝 Pycord,原程式碼不需做任何變動。
:::
- 移除 discord.py 套件
```python
pip uninstall discord.py
```
- 安裝 Pycord 套件
```python
pip install py-cord
```
- 參考資料:
- https://docs.pycord.dev/en/stable/index.html
## 應用程式指令(範例)
```python
@bot.slash_command(name="ping", description="檢查機器人的延遲")
async def ping(ctx):
start = time.time()
message = await ctx.respond('等待中...')
end = time.time()
latency = (end - start) * 1000
await message.edit_original_response(content=f'{latency:.1f} ms')
```

```python
# /尋找課程
@bot.slash_command(name="搜尋課程", description="搜尋目前開課課程")
@option("類別", description="選擇要搜尋的類別", choices=["老師", "課程"])
@option(
"關鍵字",
description="請輸入關鍵字",
required=True
)
async def 尋找課程(
ctx: discord.ApplicationContext,
類別: str,
關鍵字: str,
):
temp = 0
course_data = search(類別,關鍵字)
for course in course_data:
temp += 1
embed=discord.Embed(title="[" + course['授課老師'] + "] " + course['科目名稱'], color=0x00b4ff)
embed.set_author(name=course['選課代號'])
embed.set_footer(text=course['上課班級'] + " " + course['修別'] + " " + course['上課時間地點'])
if temp == 0:
await ctx.respond(embed=embed)
else:
await ctx.send(embed=embed)
```
###### tags: `討論共筆`