dcchbot 1.0.0__py3-none-any.whl → 1.2.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dcchbot/__init__.py +3 -2
- dcchbot/__main__.py +3 -0
- dcchbot/main.py +147 -161
- {dcchbot-1.0.0.dist-info → dcchbot-1.2.7.dist-info}/METADATA +1 -1
- dcchbot-1.2.7.dist-info/RECORD +9 -0
- dcchbot-1.2.7.dist-info/entry_points.txt +2 -0
- dcchbot-1.0.0.dist-info/RECORD +0 -8
- dcchbot-1.0.0.dist-info/entry_points.txt +0 -2
- {dcchbot-1.0.0.dist-info → dcchbot-1.2.7.dist-info}/WHEEL +0 -0
- {dcchbot-1.0.0.dist-info → dcchbot-1.2.7.dist-info}/licenses/LICENSE +0 -0
- {dcchbot-1.0.0.dist-info → dcchbot-1.2.7.dist-info}/top_level.txt +0 -0
dcchbot/__init__.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#init
|
2
|
-
|
2
|
+
from .main import run
|
3
|
+
print("Discord chinese bot v1.5.0 ok")
|
3
4
|
print("If bot cannot work,run:")
|
4
5
|
print(" batch")
|
5
6
|
print("pip install discord.py")
|
6
7
|
print("It well work")
|
7
8
|
print("by I_am_from_taiwan")
|
8
|
-
|
9
|
+
run()
|
dcchbot/__main__.py
ADDED
dcchbot/main.py
CHANGED
@@ -1,168 +1,154 @@
|
|
1
1
|
# v1.0.0
|
2
|
-
import discord
|
3
|
-
from discord.ext import commands
|
4
|
-
from discord import app_commands
|
5
|
-
from datetime import timedelta
|
6
|
-
import os
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
# 一般指令
|
30
|
-
|
31
|
-
@bot.tree.command(name="hello", description="跟你說哈囉")
|
32
|
-
async def hello(interaction: discord.Interaction):
|
33
|
-
await interaction.response.send_message(f"哈囉 {interaction.user.mention}")
|
34
|
-
|
35
|
-
@bot.tree.command(name="ping", description="顯示延遲")
|
36
|
-
async def ping(interaction: discord.Interaction):
|
37
|
-
await interaction.response.send_message(f"延遲:{round(bot.latency * 1000)}ms")
|
38
|
-
|
39
|
-
@bot.tree.command(name="say", description="讓機器人說話")
|
40
|
-
@app_commands.describe(message="你想說的話")
|
41
|
-
async def say(interaction: discord.Interaction, message: str):
|
42
|
-
await interaction.response.send_message(message)
|
43
|
-
|
44
|
-
|
45
|
-
# 權限檢查
|
46
|
-
|
47
|
-
def is_admin(interaction: discord.Interaction) -> bool:
|
48
|
-
return interaction.user.guild_permissions.administrator
|
49
|
-
|
50
|
-
|
51
|
-
# 管理指令(不含 emoji)
|
52
|
-
|
53
|
-
@bot.tree.command(name="ban", description="封鎖使用者(限管理員)")
|
54
|
-
@app_commands.describe(member="要封鎖的使用者", reason="封鎖原因")
|
55
|
-
async def ban(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
|
56
|
-
if not is_admin(interaction):
|
57
|
-
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
58
|
-
try:
|
59
|
-
await member.ban(reason=reason)
|
60
|
-
await interaction.response.send_message(f"{member.mention} 已被封鎖。原因:{reason}")
|
61
|
-
except discord.Forbidden:
|
62
|
-
await interaction.response.send_message("無法封鎖對方,可能因為權限不足或目標層級過高。", ephemeral=True)
|
63
|
-
|
64
|
-
@bot.tree.command(name="kick", description="踢出使用者(限管理員)")
|
65
|
-
@app_commands.describe(member="要踢出的使用者", reason="踢出原因")
|
66
|
-
async def kick(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
|
67
|
-
if not is_admin(interaction):
|
68
|
-
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
69
|
-
try:
|
70
|
-
await member.kick(reason=reason)
|
71
|
-
await interaction.response.send_message(f"{member.mention} 已被踢出。原因:{reason}")
|
72
|
-
except discord.Forbidden:
|
73
|
-
await interaction.response.send_message("無法封鎖對方,可能因為權限不足或目標層級過高。", ephemeral=True)
|
74
|
-
|
75
|
-
@bot.tree.command(name="timeout", description="暫時禁言使用者(限管理員)")
|
76
|
-
@app_commands.describe(member="要禁言的使用者", seconds="禁言秒數", reason="禁言原因")
|
77
|
-
async def timeout(interaction: discord.Interaction, member: discord.Member, seconds: int, reason: str = "未提供原因"):
|
78
|
-
if not is_admin(interaction):
|
79
|
-
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
80
|
-
try:
|
81
|
-
await member.timeout_for(timedelta(seconds=seconds), reason=reason)
|
82
|
-
await interaction.response.send_message(f"{member.mention} 已被禁言 {seconds} 秒。原因:{reason}")
|
83
|
-
except Exception as e:
|
84
|
-
await interaction.response.send_message(f"無法禁言:{e}")
|
85
|
-
except discord.Forbidden:
|
86
|
-
await interaction.response.send_message("無法對方,可能因為權限不足或目標層級過高。", ephemeral=True)
|
87
|
-
|
88
|
-
@bot.tree.command(name="warn", description="警告使用者(限管理員)")
|
89
|
-
@app_commands.describe(member="要警告的使用者", reason="警告原因")
|
90
|
-
async def warn(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
|
91
|
-
if not is_admin(interaction):
|
92
|
-
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
93
|
-
await interaction.response.send_message(f"{member.mention} 已被警告。原因:{reason}")
|
94
|
-
try:
|
95
|
-
await member.send(f"你在伺服器 {interaction.guild.name} 被警告:{reason}")
|
96
|
-
except:
|
97
|
-
await interaction.followup.send("無法傳送私人訊息給該用戶。")
|
98
|
-
# ⏹️ GUI 控制面板 View
|
99
|
-
class ModerationView(discord.ui.View):
|
100
|
-
def __init__(self, member: discord.Member, author: discord.Member):
|
101
|
-
super().__init__(timeout=60) # GUI 存活時間秒
|
102
|
-
self.member = member
|
103
|
-
self.author = author
|
104
|
-
|
105
|
-
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
106
|
-
# 僅限原始執行者互動
|
107
|
-
return interaction.user.id == self.author.id
|
108
|
-
|
109
|
-
@discord.ui.button(label="警告", style=discord.ButtonStyle.secondary)
|
110
|
-
async def warn_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
3
|
+
def run():
|
4
|
+
import discord
|
5
|
+
from discord.ext import commands
|
6
|
+
from discord import app_commands
|
7
|
+
from datetime import timedelta
|
8
|
+
|
9
|
+
intents = discord.Intents.all()
|
10
|
+
intents.guilds = True
|
11
|
+
intents.members = True
|
12
|
+
intents.message_content = True
|
13
|
+
|
14
|
+
bot = commands.Bot(command_prefix="!", intents=intents)
|
15
|
+
OWNER_ID = 1317800611441283139 # 不要加引號!
|
16
|
+
|
17
|
+
def is_admin(interaction: discord.Interaction) -> bool:
|
18
|
+
return interaction.user.guild_permissions.administrator
|
19
|
+
|
20
|
+
@bot.event
|
21
|
+
async def on_ready():
|
22
|
+
await bot.wait_until_ready()
|
111
23
|
try:
|
112
|
-
await
|
113
|
-
|
114
|
-
pass
|
115
|
-
await interaction.response.send_message(f"{self.member.mention} 已被警告。", ephemeral=True)
|
116
|
-
|
117
|
-
@discord.ui.button(label="禁言 60 秒", style=discord.ButtonStyle.primary)
|
118
|
-
async def timeout_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
119
|
-
try:
|
120
|
-
await self.member.timeout_for(timedelta(seconds=60), reason="由管理員 GUI 操作禁言")
|
121
|
-
await interaction.response.send_message(f"{self.member.mention} 已被禁言 60 秒。", ephemeral=True)
|
24
|
+
synced = await bot.tree.sync()
|
25
|
+
print(f"已同步 {len(synced)} 個 slash 指令")
|
122
26
|
except Exception as e:
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
27
|
+
print(f"同步 slash 指令失敗:{e}")
|
28
|
+
print(f'機器人上線:{bot.user}')
|
29
|
+
|
30
|
+
@bot.tree.command(name="hello", description="跟你說哈囉")
|
31
|
+
async def hello(interaction: discord.Interaction):
|
32
|
+
await interaction.response.send_message(f"哈囉 {interaction.user.mention}")
|
33
|
+
|
34
|
+
@bot.tree.command(name="ping", description="顯示延遲")
|
35
|
+
async def ping(interaction: discord.Interaction):
|
36
|
+
await interaction.response.send_message(f"延遲:{round(bot.latency * 1000)}ms")
|
37
|
+
|
38
|
+
@bot.tree.command(name="say", description="讓機器人說話")
|
39
|
+
@app_commands.describe(message="你想說的話")
|
40
|
+
async def say(interaction: discord.Interaction, message: str):
|
41
|
+
await interaction.response.send_message(message)
|
42
|
+
|
43
|
+
@bot.tree.command(name="ban", description="封鎖使用者(限管理員)")
|
44
|
+
@app_commands.describe(member="要封鎖的使用者", reason="封鎖原因")
|
45
|
+
async def ban(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
|
46
|
+
if not is_admin(interaction):
|
47
|
+
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
127
48
|
try:
|
128
|
-
await
|
129
|
-
await interaction.response.send_message(f"{
|
130
|
-
except
|
131
|
-
await interaction.response.send_message(
|
132
|
-
|
133
|
-
@
|
134
|
-
|
49
|
+
await member.ban(reason=reason)
|
50
|
+
await interaction.response.send_message(f"{member.mention} 已被封鎖。原因:{reason}")
|
51
|
+
except discord.Forbidden:
|
52
|
+
await interaction.response.send_message("無法封鎖對方,可能因為權限不足或目標層級過高。", ephemeral=True)
|
53
|
+
|
54
|
+
@bot.tree.command(name="kick", description="踢出使用者(限管理員)")
|
55
|
+
@app_commands.describe(member="要踢出的使用者", reason="踢出原因")
|
56
|
+
async def kick(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
|
57
|
+
if not is_admin(interaction):
|
58
|
+
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
59
|
+
try:
|
60
|
+
await member.kick(reason=reason)
|
61
|
+
await interaction.response.send_message(f"{member.mention} 已被踢出。原因:{reason}")
|
62
|
+
except discord.Forbidden:
|
63
|
+
await interaction.response.send_message("無法踢出對方,可能因為權限不足或目標層級過高。", ephemeral=True)
|
64
|
+
|
65
|
+
@bot.tree.command(name="timeout", description="暫時禁言使用者(限管理員)")
|
66
|
+
@app_commands.describe(member="要禁言的使用者", seconds="禁言秒數", reason="禁言原因")
|
67
|
+
async def timeout(interaction: discord.Interaction, member: discord.Member, seconds: int, reason: str = "未提供原因"):
|
68
|
+
if not is_admin(interaction):
|
69
|
+
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
135
70
|
try:
|
136
|
-
await
|
137
|
-
await interaction.response.send_message(f"{
|
71
|
+
await member.timeout_for(timedelta(seconds=seconds), reason=reason)
|
72
|
+
await interaction.response.send_message(f"{member.mention} 已被禁言 {seconds} 秒。原因:{reason}")
|
138
73
|
except Exception as e:
|
139
|
-
await interaction.response.send_message(f"
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
74
|
+
await interaction.response.send_message(f"無法禁言:{e}")
|
75
|
+
|
76
|
+
@bot.tree.command(name="warn", description="警告使用者(限管理員)")
|
77
|
+
@app_commands.describe(member="要警告的使用者", reason="警告原因")
|
78
|
+
async def warn(interaction: discord.Interaction, member: discord.Member, reason: str = "未提供原因"):
|
79
|
+
if not is_admin(interaction):
|
80
|
+
return await interaction.response.send_message("你沒有權限執行此指令。", ephemeral=True)
|
81
|
+
await interaction.response.send_message(f"{member.mention} 已被警告。原因:{reason}")
|
82
|
+
try:
|
83
|
+
await member.send(f"你在伺服器 {interaction.guild.name} 被警告:{reason}")
|
84
|
+
except:
|
85
|
+
await interaction.followup.send("無法傳送私人訊息給該用戶。")
|
86
|
+
|
87
|
+
class ModerationView(discord.ui.View):
|
88
|
+
def __init__(self, member: discord.Member, author: discord.Member):
|
89
|
+
super().__init__(timeout=60)
|
90
|
+
self.member = member
|
91
|
+
self.author = author
|
92
|
+
|
93
|
+
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
94
|
+
return interaction.user.id == self.author.id
|
95
|
+
|
96
|
+
@discord.ui.button(label="警告", style=discord.ButtonStyle.secondary)
|
97
|
+
async def warn_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
98
|
+
try:
|
99
|
+
await self.member.send(f"你在伺服器 {interaction.guild.name} 被警告。請注意言行。")
|
100
|
+
except:
|
101
|
+
pass
|
102
|
+
await interaction.response.send_message(f"{self.member.mention} 已被警告。", ephemeral=True)
|
103
|
+
|
104
|
+
@discord.ui.button(label="禁言 60 秒", style=discord.ButtonStyle.primary)
|
105
|
+
async def timeout_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
106
|
+
try:
|
107
|
+
await self.member.timeout_for(timedelta(seconds=60), reason="由管理員 GUI 操作禁言")
|
108
|
+
await interaction.response.send_message(f"{self.member.mention} 已被禁言 60 秒。", ephemeral=True)
|
109
|
+
except Exception as e:
|
110
|
+
await interaction.response.send_message(f"禁言失敗:{e}", ephemeral=True)
|
111
|
+
|
112
|
+
@discord.ui.button(label="踢出", style=discord.ButtonStyle.danger)
|
113
|
+
async def kick_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
114
|
+
try:
|
115
|
+
await self.member.kick(reason="由管理員 GUI 操作踢出")
|
116
|
+
await interaction.response.send_message(f"{self.member.mention} 已被踢出。", ephemeral=True)
|
117
|
+
except Exception as e:
|
118
|
+
await interaction.response.send_message(f"踢出失敗:{e}", ephemeral=True)
|
119
|
+
|
120
|
+
@discord.ui.button(label="封鎖", style=discord.ButtonStyle.danger)
|
121
|
+
async def ban_button(self, interaction: discord.Interaction, button: discord.ui.Button):
|
122
|
+
try:
|
123
|
+
await self.member.ban(reason="由管理員 GUI 操作封鎖")
|
124
|
+
await interaction.response.send_message(f"{self.member.mention} 已被封鎖。", ephemeral=True)
|
125
|
+
except Exception as e:
|
126
|
+
await interaction.response.send_message(f"封鎖失敗:{e}", ephemeral=True)
|
127
|
+
|
128
|
+
@bot.tree.command(name="moderate", description="打開管理 GUI 面板")
|
129
|
+
@app_commands.describe(member="要管理的對象")
|
130
|
+
async def moderate(interaction: discord.Interaction, member: discord.Member):
|
131
|
+
if not is_admin(interaction):
|
132
|
+
return await interaction.response.send_message("你沒有權限使用此指令。", ephemeral=True)
|
133
|
+
view = ModerationView(member, interaction.user)
|
134
|
+
await interaction.response.send_message(
|
135
|
+
f"請選擇對 {member.mention} 的操作:",
|
136
|
+
view=view,
|
137
|
+
ephemeral=True
|
138
|
+
)
|
139
|
+
|
140
|
+
@bot.tree.command(name="stop", description="關閉機器人(限擁有者)")
|
141
|
+
async def stop(interaction: discord.Interaction):
|
142
|
+
if interaction.user.id != OWNER_ID:
|
143
|
+
return await interaction.response.send_message("只有擁有者可以使用此指令。", ephemeral=True)
|
144
|
+
await interaction.response.send_message("機器人即將關閉。")
|
145
|
+
await bot.close()
|
146
|
+
|
147
|
+
# 🔐 請使用者輸入 Token
|
148
|
+
token = input("請輸入你的 Discord Bot Token:\n> ").strip()
|
149
|
+
try:
|
150
|
+
bot.run(token)
|
151
|
+
except discord.LoginFailure:
|
152
|
+
print("Token 無效,請重新確認。")
|
153
|
+
except Exception as e:
|
154
|
+
print(f"發生錯誤:{e}")
|
@@ -0,0 +1,9 @@
|
|
1
|
+
dcchbot/__init__.py,sha256=NRneOR4yOEyDtsiN61aoYpGNozTiAdVI0_vN6as1KoM,228
|
2
|
+
dcchbot/__main__.py,sha256=5FwoJspcKFt5_1AlXoxlWROiQSp9wgnFEltU6ufz9QE,30
|
3
|
+
dcchbot/main.py,sha256=E1peFrb8It75iUiELV2PjiZjwm_-hvsQcWBR4Lsz8bs,8446
|
4
|
+
dcchbot-1.2.7.dist-info/licenses/LICENSE,sha256=l3hyIOCB7NYorC-bjV5yZM0PgAJbMgAWNLE644dR7H4,1065
|
5
|
+
dcchbot-1.2.7.dist-info/METADATA,sha256=mjUZLdaawbq96bgUgUWXRRYv5mlqOIgYa9jVRQU4sr0,446
|
6
|
+
dcchbot-1.2.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
7
|
+
dcchbot-1.2.7.dist-info/entry_points.txt,sha256=90T16CGc_Tx-4pFaLCcbuuh7Vi9l4gsLovBkydqxP9Y,45
|
8
|
+
dcchbot-1.2.7.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
9
|
+
dcchbot-1.2.7.dist-info/RECORD,,
|
dcchbot-1.0.0.dist-info/RECORD
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
dcchbot/__init__.py,sha256=STTg67Y5Z2qXbhK-IP8sOVww8wg-BveJUJt4IpmyqKE,206
|
2
|
-
dcchbot/main.py,sha256=wrWAChkaxeRknQiiUIh6MMlzFhGqHzjjBlPYYOA3RX0,8265
|
3
|
-
dcchbot-1.0.0.dist-info/licenses/LICENSE,sha256=l3hyIOCB7NYorC-bjV5yZM0PgAJbMgAWNLE644dR7H4,1065
|
4
|
-
dcchbot-1.0.0.dist-info/METADATA,sha256=WzCWiIN282maiyQ05cDl6g8gdMlvAs8jVvTn2MEE_N0,446
|
5
|
-
dcchbot-1.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
6
|
-
dcchbot-1.0.0.dist-info/entry_points.txt,sha256=HiaJ3uj4ccVT8k20yGN507iSL3s7r6Jct7dDuQ0FOQI,41
|
7
|
-
dcchbot-1.0.0.dist-info/top_level.txt,sha256=jiDTz8UmwZgXN9KzokwDRYhoWxsVmWcnqmrANeTFMck,8
|
8
|
-
dcchbot-1.0.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|