|
42 | 42 | with open('setting.json', 'r') as _jfile: |
43 | 43 | jdata = json.load(_jfile) |
44 | 44 | bot = commands.Bot(command_prefix=commands.when_mentioned_or(jdata['command_prefix']), intents=intents) |
| 45 | +start_time = datetime.now() |
45 | 46 | version = "v3.0.0alpha" |
46 | 47 | logger.info(f"[init] Bot is now starting...") |
47 | 48 |
|
@@ -109,6 +110,98 @@ async def help(ctx, command: str = "all", page: int = 1): |
109 | 110 | await ctx.send(lang['help.not_found'].format(user=jdata['user'])) |
110 | 111 |
|
111 | 112 |
|
| 113 | +@bot.command(name='load', aliases=lang['load.aliases'], brief=lang['load.brief'], description=lang['load.description']) |
| 114 | +async def load(ctx, extension): |
| 115 | + if await bot.is_owner(ctx.author): |
| 116 | + bot.load_extension(F'cmds.{extension}') |
| 117 | + await ctx.send(lang['load.loaded'].format(extension=extension)) |
| 118 | + logger.debug(f'[load] loaded extension: {extension}') |
| 119 | + else: |
| 120 | + await ctx.send(embed=discord.Embed(title=lang['load.error.title'], description=lang['load.error.description'].format(owner=bot.owner_id), color=0xff0000)) |
| 121 | + |
| 122 | + |
| 123 | +@bot.command(name='unload', aliases=lang['unload.aliases'], brief=lang['unload.brief'], description=lang['unload.description']) |
| 124 | +async def unload(ctx, extension): |
| 125 | + if await bot.is_owner(ctx.author): |
| 126 | + bot.unload_extension(F'cmds.{extension}') |
| 127 | + await ctx.send(lang['unload.unloaded'].format(extension=extension)) |
| 128 | + logger.debug(f'[unload] unloaded extension: {extension}') |
| 129 | + else: |
| 130 | + await ctx.send(embed=discord.Embed(title=lang['unload.error.title'], description=lang['unload.error.description'].format(owner=bot.owner_id), color=0xff0000)) |
| 131 | + |
| 132 | + |
| 133 | +@bot.command(name='reload', aliases=lang['reload.aliases'], brief=lang['reload.brief'], description=lang['reload.description']) |
| 134 | +async def reload(ctx, extension): |
| 135 | + if await bot.is_owner(ctx.author): |
| 136 | + bot.reload_extension(F'cmds.{extension}') |
| 137 | + await ctx.send(lang['reload.reloaded'].format(extension=extension)) |
| 138 | + logger.debug(f'[reload] reloaded extension: {extension}') |
| 139 | + else: |
| 140 | + await ctx.send(embed=discord.Embed(title=lang['reload.error.title'], description=lang['reload.error.description'].format(owner=bot.owner_id), color=0xff0000)) |
| 141 | +# 機器人關閉系統-------------------------------------------- |
| 142 | + |
| 143 | + |
| 144 | +@bot.command(name='disconnect', aliases=lang['disconnect.aliases'], brief=lang['disconnect.brief'], description=lang['disconnect.description'].format(owner=bot.owner_id)) |
| 145 | +async def turn_off_bot(ctx): |
| 146 | + if await bot.is_owner(ctx.author): |
| 147 | + await ctx.send(lang['disconnect.disconnected']) |
| 148 | + logger.info('[disconnect] bot is now closing') |
| 149 | + await bot.close() |
| 150 | + else: |
| 151 | + await ctx.send(embed=discord.Embed(title=lang['disconnect.error.title'], description=lang['disconnect.error.description'].format(owner=bot.owner_id), color=0xff0000)) |
| 152 | + |
| 153 | + |
| 154 | +@bot.command(name='status', aliases=lang['status.aliases'], brief=lang['status.brief'], description=lang['status.description'].format(owner=bot.owner_id)) |
| 155 | +async def status(ctx): |
| 156 | + if await bot.is_owner(ctx.message.author): |
| 157 | + embed = discord.Embed(title=lang['status.embed.title']) |
| 158 | + embed.add_field(name=lang['status.embed.field.ping'], value=f"{round(bot.latency*1000)}ms", inline=False) |
| 159 | + perms = ">>> " |
| 160 | + for name, value in ctx.channel.permissions_for(ctx.me): |
| 161 | + if value == True: |
| 162 | + perms += name + '\n' |
| 163 | + embed.add_field(name=lang['status.embed.field.perms'], value=perms, inline=True) |
| 164 | + exts = ">>> " |
| 165 | + for ext in bot.extensions: |
| 166 | + exts += ext.replace("cmds.", "")+'\n' |
| 167 | + embed.add_field(name=lang['status.embed.field.exts'], value=exts, inline=True) |
| 168 | + uptime = datetime.now()-start_time |
| 169 | + embed.set_footer(text=lang['status.embed.footer.time'].format( |
| 170 | + days=uptime.days, hours=int(uptime.seconds / 3600), |
| 171 | + minutes=int(uptime.seconds % 3600 / 60), |
| 172 | + seconds=uptime.seconds % 3600 % 60) + version) |
| 173 | + await ctx.send(embed=embed) |
| 174 | + else: |
| 175 | + await ctx.send(embed=discord.Embed(title=lang['status.error.title'], description=lang['status.error.description'].format(owner=bot.owner_id))) |
| 176 | + |
| 177 | + |
| 178 | +@bot.command(name='sponsor', aliases=lang['sponsor.aliases'], description=lang['sponsor.description']) |
| 179 | +async def sponsor(ctx): |
| 180 | + embed = discord.Embed(title=lang['sponsor.embed.title'], description=lang['sponsor.embed.description'], color=0xff424d, url="https://patreon.com/join/lonnstyle") |
| 181 | + embed.set_thumbnail(url="https://i.imgur.com/CCYuxwH.png") |
| 182 | + await ctx.send(embed=embed) |
| 183 | + |
| 184 | + |
| 185 | +@bot.command(name='documentation', aliases=lang['documentation.aliases'], description=lang['documentation.description']) |
| 186 | +async def documentation(ctx): |
| 187 | + embed = discord.Embed(title=lang['documentation.embed.title'], description=lang['documentation.embed.description'], color=0x2980b9, url=lang['documentation.embed.url']) |
| 188 | + await ctx.send(embed=embed) |
| 189 | + |
| 190 | +for filename in os.listdir('./cmds'): |
| 191 | + if filename.endswith('.py'): |
| 192 | + bot.load_extension(f'cmds.{filename[:-3]}') |
| 193 | + |
| 194 | +commands = {} |
| 195 | +for extension in bot.extensions: |
| 196 | + package = extension |
| 197 | + name = extension[5:] |
| 198 | + tags = getattr(__import__(package, fromlist=[name]), name) |
| 199 | + try: |
| 200 | + commands[name] = tags.tag |
| 201 | + except: |
| 202 | + pass |
| 203 | + |
| 204 | + |
112 | 205 | @bot.listen() |
113 | 206 | async def on_command_error(ctx, error): |
114 | 207 | owner = await bot.application_info() |
|
0 commit comments