async def test(self, ctx): commands = { "0": { "command": self.outwords, "message": ctx.channel.send("?outwords"), "enabled": True, "startmsg": "Start outwords" }, "1": { "command": self.loadwords, "message": ctx.channel.send("?loadwords"), "enabled": True, "startmsg": "Start loadwords" }, "2": { "command": self.savewords, "message": ctx.channel.send("?savewords"), "enabled": True, "startmsg": "Start savewords" }, "3": { "command": self.addword, "message": ctx.channel.send("?addword jonk God"), "enabled": True, "startmsg": "Start addword" }, #"4": {"command": self.removeword, "message": ctx.channel.send("?removeword jonk God"), "enabled": True, "startmsg": "Start removeword"}, "5": { "command": self.download, "message": ctx.channel.send("?download FydoDictionary.txt"), "enabled": True, "startmsg": "Start download" }, "6": { "command": self.translateit, "message": ctx.channel.send("?translateit"), "enabled": True, "startmsg": "Start translateit" }, "7": { "command": self.translateid, "message": ctx.channel.send("?translateid"), "enabled": True, "startmsg": "Start translateid" }, "8": { "command": self.fydodebug, "message": ctx.channel.send("?fydodebug"), "enabled": True, "startmsg": "Start fydodebug" } } for command in commands.values(): print(command['startmsg']) print(command['command']) print(await command['message'])
def __init__(self, commands: Dict[commands.Cog, List[commands.Command]]): cogs = sorted(commands.keys(), key=lambda c: c.qualified_name) self.commands = commands super().__init__(cogs, per_page=4) total_commands = 0 for commands in commands.values(): total_commands += len(commands) self.total_commands = total_commands
async def help(ctx, command: str = "all", page: int = 1): fields = 0 embed = discord.Embed(title=lang['help.embed.title'], color=0xccab2b) embed.set_author(name="Patreon", url="https://patreon.com/join/lonnstyle", icon_url="https://i.imgur.com/CCYuxwH.png") if command == "all": for command in bot.commands: if command.brief != None: if (page - 1) * 25 <= fields <= page * 25 - 1: embed.add_field( name=f"{jdata['command_prefix']}{command.name}", value=command.brief, inline=True) fields += 1 embed.set_footer(text=lang['help.embed.footer'].format( command_prefix=jdata['command_prefix'], page=page, total=int((fields - fields % 25) / 25 + 1))) await ctx.send(embed=embed) elif command in commands.values(): for botcommand in bot.commands: if command == "common" and botcommand.cog_name == None: if (page - 1) * 25 < fields <= page * 25 - 1: embed.add_field( name=f"{jdata['command_prefix']}{botcommand.name}", value=botcommand.brief) fields += 1 for ext, tag in commands.items(): if tag == command and ext == botcommand.cog_name: if (page - 1) * 25 < fields <= page * 25 - 1: embed.add_field( name=f"{jdata['command_prefix']}{botcommand.name}", value=botcommand.brief) fields += 1 embed.set_footer(text=lang['help.embed.footer'].format( command_prefix=jdata['command_prefix'], page=page, total=int((fields - fields % 25) / 25 + 1))) await ctx.send(embed=embed) else: for botcommand in bot.commands: if botcommand.name == command: aliases = botcommand.name params = "" for param in botcommand.clean_params: params += f" <{param}>" for alias in botcommand.aliases: aliases += f"|{alias}" embed.add_field( name=f"{jdata['command_prefix']}[{aliases}]{params}", value=botcommand.description) await ctx.send(embed=embed) return await ctx.send(lang['help.not_found'].format(user=jdata['user']))
async def convert(cls, ctx, argument): member, data = await super().convert(ctx, argument) command_usages = {} for payload in data: command = command_usages.setdefault(payload["command"], []) command.append(payload["time_used"]) for command in command_usages.values(): command.sort(reverse=True) commands = Counter(payload["command"] for payload in data) total_usage = sum(v for v in commands.values()) return cls(member, commands, command_usages, total_usage)
def max_name_size(self): """int: Returns the largest name length of a command or if it has subcommands the largest subcommand name.""" try: commands = self.command.all_commands if not self.is_cog( ) else self.context.bot.all_commands if commands: return max( map( lambda c: len(c.name) if self.show_hidden or not c.hidden else 0, commands.values())) return 0 except AttributeError: return len(self.command.name)
async def help(ctx, command:str="all", page:int=1): fields = 0 embed = discord.Embed(title="幫助列表",color=0xccab2b) if command == "all": for command in bot.commands: if command.brief != None: if (page-1)*25<fields<=page*25-1: embed.add_field(name=f"{jdata['command_prefix']}{command.name}", value=command.brief, inline=True) fields += 1 embed.set_footer(text=f"第{page}/{int((fields-fields%25)/25+1)}頁") await ctx.send(embed=embed) elif command in commands.values(): for botcommand in bot.commands: if command == "common" and botcommand.cog_name == None: if (page-1)*25<fields<=page*25-1: embed.add_field(name=f"{jdata['command_prefix']}{botcommand.name}", value=botcommand.brief) fields += 1 for ext,tag in commands.items(): if tag == command and ext == botcommand.cog_name: if (page-1)*25<fields<=page*25-1: embed.add_field(name=f"{jdata['command_prefix']}{botcommand.name}", value=botcommand.brief) fields += 1 embed.set_footer(text=f"第{page}/{int((fields-fields%25)/25+1)}頁") await ctx.send(embed=embed) else: for botcommand in bot.commands: if botcommand.name == command: aliases = botcommand.name params = "" for param in botcommand.clean_params: params += f"<{param}>" for alias in botcommand.aliases: aliases += f"|{alias}" embed.add_field(name=f"{jdata['command_prefix']}[{aliases}] {params}",value=botcommand.description) await ctx.send(embed=embed) return await ctx.send("找不到您要問的呢")
async def help(self, ctx, command=None): commands = { 'UTILITY': { 'help': { 'description': 'Displays commands for DemaBot', 'usage': '!help [command]' }, 'ping': { 'description': 'PONG!', 'usage': '!ping' } }, 'FUN': { 'tag': { 'description': 'Allows you to create a tag that others can use', 'usage': '!tag` `!tag create' }, 'hug': { 'description': 'Send a cute hug gif to another user', 'usage': '!hug [user]' } }, 'ECONOMY': { 'bal': { 'description': 'Displays your current balance', 'usage': '!bal' }, 'top': { 'description': 'Lists the richest users in the server', 'usage': '!top' }, 'daily': { 'description': 'Gives you £100 every day plus a bonus reward for a 7 day streak', 'usage': '!daily' }, 'donate': { 'description': 'Donate money to another user', 'usage': '!donate [@user] [amount]' }, 'shop': { 'description': 'Displays the shop and allows you to buy items', 'usage': '!shop' }, 'role': { 'description': 'Allows you to choose from your purchased roles', 'usage': '!role' } } } if command is None: embed = discord.Embed(title="Help for DemaBot") embed.set_footer(text="Use `!help [command]` for more info") for name, cat in commands.items(): coms = [] for cname, com in cat.items(): coms.append(f"**{cname}** - {com['description']}") embed.add_field(name=name.upper(), value='\n'.join(coms), inline=False) await ctx.send(embed=embed) else: found = False for cat in commands.values(): for name, com in cat.items(): if name == command: embed = discord.Embed(title=f"Help for {name}") embed.add_field(name='Description', value=com['description'], inline=False) embed.add_field(name='Usage', value=f"`{com['usage']}`", inline=False) await ctx.send(embed=embed) found = True return if found == True: return if found == False: embed = discord.Embed( title="ERROR", description= "The command you entered could not be found. Use `!help` to view a list of commands." ) await ctx.send(embed=embed)
def max_name_size(self): """int : Returns the largest name length of a command or if it has subcommands the largest subcommand name.""" try: commands = self.command.commands if not self.is_cog() else self.context.bot.commands if commands: return max(map(lambda c: len(c.name) if self.show_hidden or not c.hidden else 0, commands.values())) return 0 except AttributeError: return len(self.command.name)