講師:歪伊恩、777
我是用3.9.10寫,新版不確定模組更新狀況
拜託記得打勾!
拜託記得打勾!
拜託記得打勾!
不要找不到才來問我在哪...
反正我是用這個
聽說有人會用
或者你有更好的,反正選個喜歡的就好
開啟cmd
輸入這串:
好欸可以開始寫了
pip install discord.py
在cmd中輸入:
有看到這個就代表有了喔~
pip list
創建一隻bot
設定的話先不要動
然後記得複製token
通常在這裡
URL
-->bot打勾
-->最下面有連結
-->邀請進伺服器
import discord
from discord.ext import commands
intents= discord.Intents.all()
bot = commands.Bot(command_prefix="你要的觸發符號",intents = intents)
bot.run("你的TOKEN")
@bot.event
async def on_ready():
print(">>bot is online<<")
@bot.event
async def on_member_join(member):
channel = bot.get_channel(頻道碼)
await channel.send(f'{member}join!')
@bot.event
async def on_member_remove(member):
channel = bot.get_channel(頻道碼)
await channel.send(f'{member}leave!')
@bot.command()
async def ping(ctx):
await ctx.send(f'{round(bot.latency*1000)}(ms)')
其實偷用到了ctx不過我哪有差
最簡單的也是最基礎的ping
補充一下
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current Dir (external)",
"type": "python",
"request": "launch",
"cwd":"${fileDirname}",
"program": "${file}",
"console": "externalTerminal",
"env": {"PYTHONPATH": "${workspaceRoot}"},
},
{
"name": "Python: Current Dir (internal)",
"type": "python",
"request": "launch",
"cwd":"${fileDirname}",
"program": "${file}",
"console": "integratedTerminal",
"env": {"PYTHONPATH": "${workspaceRoot}"},
},
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
},
{
"name": "Python 模組",
"type": "python",
"request": "launch",
"module": "enter-your-module-name",
"justMyCode": true
}
]
}
把launch.json裡面改成這個然後debug選
Python : Current Dir (external)
下節應該會教你們怎麼看吧
好欸我水完一堂課了