SCAICT 二月主題課程Discord Bot環境問題替代方案
如果環境有問題
- pip 無法安裝
- py-cord 安裝有問題
- python有問題
- windows環境有問題
請按照以下步驟使用Replit來製作discord bot
操作步驟:
先到 Replit註冊帳號
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
註冊好後 左側Create Repl
創建專案
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
左側Template
選擇Python
右側Title命名你專案名稱 -> 然後點Create Repl
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
創建完後就會進到開發頁面ㄌ! (如果main.py
裡面有code的話刪掉即可)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
左側Tools
點Packages
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
在左側Packges
輸入py-cord
找到後按 Install
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
輸入discord2
並安裝
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
之後就可以正常撰寫codeㄌ
點上方的Run
運行程式

上線成功 功能正常


token儲存
前面講到 token
代表著你機器人的金鑰 不可以外流
但在Replit的免費版裡 所以專案都是對外公開的
所以當然不能把token赤裸裸的放在code上面
到左方Tools
選 Secrets

點 New Secret

Key的名稱可以隨便取 ex.token
Value放你的token
輸入完後按Add Secret

他會出現要求步驟import os和導入token

在程式最上方多加 import os

將 my_secret
放到 bot.run()
內替帶token(注意:bot.run(my_secret)
不需用""包住)
當然你可以換掉 my_secret
改叫做其他ㄉ

在Run一次一樣成功上線

問題區:
-
安裝完Packges後,運行程式還是出錯。
-
環境上和上課操作會有差異嗎?
-
看完教學我還是不太清楚怎麼操作@@
- 下周上課 19:00 會是助教時間 上課時會演示操作一遍 如果有問題可以提早到並提出
-
是否可以更改main.py
的檔案名稱或將他刪除
- 助教測試後砍掉
main.py
疑似會無法運行 程式直接撰寫在main.py
內即可
有問題請DC私訊 osag_
包含機器人構思、該如何寫、上週上課不了解、操作有問題
都可以私訊 我不會咬人請放心 ^ o ^

參考文獻: https://ithelp.ithome.com.tw/articles/10328428
btw 我搞到凌晨五點 下面是我發瘋的證明。
