-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAutoRole.py
37 lines (31 loc) · 1.36 KB
/
AutoRole.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from email import message
from discord.utils import get
import discord
import config
intents=discord.Intents().all() # 獲取所有的 Intents 對象
intents.message_content = True # 允許讀取消息內容
intents.members = True # 允許讀取成員
#bot=discord.Client 是我們與 Discord 連結的橋樑
bot = discord.Client(intents=intents)
#調用 event 函式庫
@bot.event
#當機器人完成啟動時
async def on_ready():
#確認連結TOKEN的BOT是否有誤
print('目前登入身份:', bot.user)
#機器人的遊戲狀態,想設什麼都可以
game = discord.Game('AutoRoleBot')
#機器人的在線狀態
await bot.change_presence(status=discord.Status.online, activity=game)
@bot.event
#當有成員加入(DC群)時
async def on_member_join(member):
#以下兩個請挑其中一個使用,不用的註解掉即可
#給予加入DC群的成員 config.id 的身分組
role = discord.utils.get(member.guild.roles, id=config.id)
#給予加入DC群的成員 config.name 的身分組
#role = discord.utils.get(member.guild.roles, id=config.name)
await member.add_roles(role)
#當然這也可以打 await message.channel.send("歡迎加入") 等做出加入DC時發送的訊息
#await message.channel.send("歡迎加入(XXX)DC群")
bot.run(config.TOKEN) #TOKEN 在 Discord Developer 的 BOT 頁面