-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdc bot.py
62 lines (48 loc) · 1.74 KB
/
dc bot.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import asyncio
import discord
import json
from pixivpy3 import *
from discord.ext import commands
from discord import app_commands
from discord.app_commands import Choice
import os
global jdata
with open('setting.json',mode='r',encoding='utf8')as jfile: #打開setting.json,模式是read,命名為jfile
jdata=json.load(jfile)
REFRESH_TOKEN="Dv72iY_Mv2vqfcAhSB98x9K_0W85PYOy7h3t9PLe_Aw"
intents=discord.Intents.all()
bot=commands.Bot(command_prefix='!',intents=intents)
tree=bot.tree
def recommend():
api= AppPixivAPI()
api.auth(refresh_token=REFRESH_TOKEN)
# @tree.command(name='test',description='just text')
# async def test(interaction: discord.Interaction):
# """hello!"""
# await interaction.response.send_message('hihi')
@bot.event #發送啟動訊息
async def on_ready():
channel=bot.get_channel(int(jdata['channel_id']))
await channel.send('機器人上線啦!') #發送訊息
print("bot上線拉") #在終端發送訊息
@bot.command() #載入檔案
async def load(ctx,extension):
bot.load_extension(f'cmds.{extension}')
await ctx.send(f'Loaded {extension} done.')
@bot.command() #卸載檔案
async def unload(ctx,extension):
bot.unload_extension(f'cmds.{extension}')
await ctx.send(f'Unloaded {extension} done.')
@bot.command() #重載檔案
async def reload(ctx,extension):
os.system("git pull")
bot.reload_extension(f'cmds.{extension}')
await ctx.send(f'Re-Loaded {extension} done.')
async def main(): #啟用Cog
async with bot:
for Filename in os.listdir('./cmds'):
if Filename.endswith('.py'):
await bot.load_extension(f"cmds.{Filename[:-3]}")
await bot.start(jdata['token'])
if __name__=="__main__": #啟動bot
asyncio.run(main())