Skip to content

Commit e8cb57d

Browse files
committed
chore: 更新版本至1.0.2
1 parent e804afb commit e8cb57d

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
token.txt
2+
slash.json
23
/.vscode
34
/.idea
45
*/__pycache__/*

Cogs/about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def about(self, interaction: discord.Interaction):
3636
)
3737
embed.add_field(
3838
name = "版本",
39-
value = "1.0.1"
39+
value = cfg["version"]
4040
)
4141
embed.add_field(
4242
name = "授權條款",

cfg.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
#
1212
# A Discord Bot for "whiter.lnstw.xyz", a Minecraft Server's bot.
1313

14+
# ================================
15+
# ○ Bot資訊設定
16+
# 齒輪:無
17+
# 如果你不知道這是做甚麼用的,
18+
# 請不要更改
19+
# ================================
20+
version: 1.0.2
21+
1422
# Bot Token請填寫在token.txt中,這裡不進行填寫
1523

1624
# ================================

main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import yaml
77
import asyncio
88
import platform
9+
import json
910

1011
# Logging
1112
logging.basicConfig(
@@ -28,6 +29,22 @@
2829
# Bot
2930
bot = commands.Bot(command_prefix='sh!', intents=discord.Intents.all())
3031

32+
async def write_slash_synced(slash: discord.app_commands.AppCommand):
33+
with open('slash.json', 'w') as f:
34+
# 取得所有指令與其說明,並存入陣列中
35+
logging.info('寫入指令同步資料')
36+
slash = []
37+
for command in bot.tree.walk_commands():
38+
logging.debug(f'指令名稱:{command.name},指令說明:{command.description}')
39+
slash.append({
40+
'name': command.name,
41+
'description': command.description
42+
})
43+
44+
logging.debug(f'指令同步資料:{slash}')
45+
json.dump(slash, f)
46+
logging.info('指令同步資料寫入成功')
47+
3148
# Cogs Slash Command
3249
@bot.event
3350
async def on_ready():
@@ -43,6 +60,7 @@ async def on_ready():
4360
OS: {platform.system()} {platform.release()}
4461
Python Version: {platform.python_version()}
4562
Discord.py Version: {discord.__version__}
63+
YunyuBot Version: {cfg["version"]}
4664
Development by 510208, Thanks for using!
4765
4866
"""
@@ -57,6 +75,7 @@ async def on_ready():
5775
slash = await bot.tree.sync()
5876
if slash:
5977
logging.info(f'指令同步完成:{slash}')
78+
await write_slash_synced(slash)
6079
else:
6180
logging.error('指令同步失敗')
6281

@@ -297,13 +316,15 @@ async def main():
297316
# 確定執行此py檔才會執行
298317
async def close_bot():
299318
# 卸載全部Cog
319+
logging.info('卸載全部Cogs')
300320
for cog in bot.cogs:
301321
logging.info(f'卸載{cog}中...')
302322
try:
303323
bot.unload_extension(f'Cogs.{cog}')
304324
logging.info(f'卸載{cog}成功')
305325
except Exception as e:
306326
logging.error(f'卸載{cog}失敗:{e}')
327+
logging.info('Bot關閉中...')
307328
await bot.close()
308329
logging.info('Bot已關閉,謝謝使用!')
309330

0 commit comments

Comments
 (0)