Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/.env | ||
/.env | ||
__pycache__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,5 @@ | ||
# 導入 套件 | ||
import discord | ||
import os | ||
from dotenv import load_dotenv | ||
from src.discordBot import DiscordBot | ||
|
||
# 取得環境設定 | ||
load_dotenv() | ||
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") | ||
# intents | ||
intents = discord.Intents.default() | ||
# client | ||
client = discord.Client(intents=intents) | ||
|
||
# event 事件處理 | ||
@client.event | ||
async def on_ready(): | ||
print(f"「{client.user}」已登入") | ||
|
||
@client.event | ||
async def on_message(message): | ||
if message.author == client.user: # 排除機器人本身的訊息 | ||
return | ||
if message.content == 'ping': | ||
await message.channel.send('pong') | ||
|
||
|
||
if __name__ == "__main__": | ||
client.run(DISCORD_TOKEN) | ||
dcBot = DiscordBot() | ||
dcBot.start() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 導入 套件 | ||
import discord | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
# 取得環境設定 | ||
load_dotenv() | ||
DISCORD_TOKEN = os.getenv("DISCORD_TOKEN") | ||
# intents | ||
intents = discord.Intents.default() | ||
intents.message_content = True | ||
# client | ||
client = discord.Client(intents=intents) | ||
|
||
class DiscordBot(): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def start(self): | ||
client.run(DISCORD_TOKEN) | ||
|
||
|
||
# event 事件處理 | ||
@client.event | ||
async def on_ready(): | ||
print(f"「{client.user}」已登入") | ||
|
||
@client.event | ||
async def on_message(message): | ||
print(message) # 印出message 內容 | ||
if message.author == client.user: # 排除機器人本身的訊息 | ||
return | ||
if message.content == 'ping': | ||
await message.channel.send('pong') |