當前位置: 首頁>>代碼示例>>Python>>正文


Python commands.Paginator方法代碼示例

本文整理匯總了Python中discord.ext.commands.Paginator方法的典型用法代碼示例。如果您正苦於以下問題:Python commands.Paginator方法的具體用法?Python commands.Paginator怎麽用?Python commands.Paginator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在discord.ext.commands的用法示例。


在下文中一共展示了commands.Paginator方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: jsk_tasks

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def jsk_tasks(self, ctx: commands.Context):
        """
        Shows the currently running jishaku tasks.
        """

        if not self.tasks:
            return await ctx.send("No currently running tasks.")

        paginator = commands.Paginator(max_size=1985)

        for task in self.tasks:
            paginator.add_line(f"{task.index}: `{task.ctx.command.qualified_name}`, invoked at "
                               f"{task.ctx.message.created_at.strftime('%Y-%m-%d %H:%M:%S')} UTC")

        interface = PaginatorInterface(ctx.bot, paginator, owner=ctx.author)
        return await interface.send_to(ctx) 
開發者ID:Gorialis,項目名稱:jishaku,代碼行數:18,代碼來源:cog_base.py

示例2: guild_role

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def guild_role(self, text: str, check=lambda role: True, list_ids=False) -> Role:
        async def converter(mes: Message):
            return discord.utils.get(self.guild.roles,
                                     id=int(mes.content.translate(digit_keeper)))

        if list_ids:
            guild: Guild = self.ctx.guild
            paginator = Paginator()
            for role in guild.roles:
                paginator.add_line(role.name + ' ' + str(role.id))

            for page in paginator.pages:
                await self.ctx.send(
                    embed=Embed(
                        color=Color.blurple(),
                        description=page))
        return await self.by_converter(
            text,
            check=check,
            converter=converter) 
開發者ID:BaseChip,項目名稱:RulesBot,代碼行數:22,代碼來源:awaiter.py

示例3: raw

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def raw(self, ctx: Context, *, message: Message, json: bool = False) -> None:
        """Shows information about the raw API response."""
        # I *guess* it could be deleted right as the command is invoked but I felt like it wasn't worth handling
        # doing this extra request is also much easier than trying to convert everything back into a dictionary again
        raw_data = await ctx.bot.http.get_message(message.channel.id, message.id)

        paginator = Paginator()

        def add_content(title: str, content: str) -> None:
            paginator.add_line(f'== {title} ==\n')
            # replace backticks as it breaks out of code blocks. Spaces seemed to be the most reasonable solution.
            # we hope it's not close to 2000
            paginator.add_line(content.replace('```', '`` `'))
            paginator.close_page()

        if message.content:
            add_content('Raw message', message.content)

        transformer = pprint.pformat if json else self.format_fields
        for field_name in ('embeds', 'attachments'):
            data = raw_data[field_name]

            if not data:
                continue

            total = len(data)
            for current, item in enumerate(data, start=1):
                title = f'Raw {field_name} ({current}/{total})'
                add_content(title, transformer(item))

        for page in paginator.pages:
            await ctx.send(page) 
開發者ID:python-discord,項目名稱:bot,代碼行數:34,代碼來源:information.py

示例4: __init__

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def __init__(self, **options):
        self.sort_commands = options.pop('sort_commands', True)
        self.commands_heading = options.pop('commands_heading', "Commands")
        self.dm_help = options.pop('dm_help', False)
        self.dm_help_threshold = options.pop('dm_help_threshold', 1000)
        self.aliases_heading = options.pop('aliases_heading', "Aliases:")
        self.no_category = options.pop('no_category', 'No Category')
        self.paginator = options.pop('paginator', None)

        if self.paginator is None:
            self.paginator = cmd.Paginator(suffix=None, prefix=None)

        super().__init__(**options) 
開發者ID:Xenon-Bot,項目名稱:xenon,代碼行數:15,代碼來源:help.py

示例5: cmds

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def cmds(self, ctx):
        """Show all custom commands."""
        if ctx.invoked_subcommand is None:
            ttl = None if ctx.message.content.endswith(' stay') else 20
            p = commands.Paginator(prefix='```css')
            cmds = read_json("commands")
            p.add_line('[List of Custom Commands]')
            msg = []
            for cmd in sorted(cmds):
                msg.append(cmd)
                if cmd == list(sorted(cmds))[-1] or len(msg) % 5 == 0 and len(msg) != 0:
                    p.add_line(', '.join(x for x in msg))
                    msg = []
            for page in p.pages:
                await ctx.send(page, delete_after=ttl)
            await ctx.message.delete()

    # List all custom commands with Links 
開發者ID:lehnification,項目名稱:Discord-SelfBot,代碼行數:20,代碼來源:cmds.py

示例6: long

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def long(self, ctx):
        """Display also their content"""
        ttl = None if ctx.message.content.endswith(' stay') else 20
        p = commands.Paginator(prefix='```css')
        cmds = read_json("commands")
        p.add_line('[List of Custom Commands]')
        width = len(max(cmds, key=len))
        for cmd in sorted(cmds):
            p.add_line('{0:<{width}}| {1}'.format(cmd, cmds.get(cmd), width=width))
        for page in p.pages:
            await ctx.send(page, delete_after=ttl)
        await ctx.message.delete() 
開發者ID:lehnification,項目名稱:Discord-SelfBot,代碼行數:14,代碼來源:cmds.py

示例7: send_traceback

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def send_traceback(destination: discord.abc.Messageable, verbosity: int, *exc_info):
    """
    Sends a traceback of an exception to a destination.
    Used when REPL fails for any reason.

    :param destination: Where to send this information to
    :param verbosity: How far back this traceback should go. 0 shows just the last stack.
    :param exc_info: Information about this exception, from sys.exc_info or similar.
    :return: The last message sent
    """

    # to make pylint stop moaning
    etype, value, trace = exc_info

    traceback_content = "".join(traceback.format_exception(etype, value, trace, verbosity)).replace("``", "`\u200b`")

    paginator = commands.Paginator(prefix='```py')
    for line in traceback_content.split('\n'):
        paginator.add_line(line)

    message = None

    for page in paginator.pages:
        message = await destination.send(page)

    return message 
開發者ID:Gorialis,項目名稱:jishaku,代碼行數:28,代碼來源:exception_handling.py

示例8: __init__

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def __init__(self, **options):
        paginator = options.pop('paginator', commands.Paginator(max_size=1985))

        super().__init__(paginator=paginator, **options) 
開發者ID:Gorialis,項目名稱:jishaku,代碼行數:6,代碼來源:help_command.py

示例9: __init__

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def __init__(self, bot: commands.Bot, paginator: commands.Paginator, **kwargs):
        if not isinstance(paginator, commands.Paginator):
            raise TypeError('paginator must be a commands.Paginator instance')

        self._display_page = 0

        self.bot = bot

        self.message = None
        self.paginator = paginator

        self.owner = kwargs.pop('owner', None)
        self.emojis = kwargs.pop('emoji', EMOJI_DEFAULT)
        self.timeout = kwargs.pop('timeout', 7200)
        self.delete_message = kwargs.pop('delete_message', False)

        self.sent_page_reactions = False

        self.task: asyncio.Task = None
        self.send_lock: asyncio.Event = asyncio.Event()
        self.update_lock: asyncio.Lock = asyncio.Semaphore(value=kwargs.pop('update_max', 2))

        if self.page_size > self.max_page_size:
            raise ValueError(
                f'Paginator passed has too large of a page size for this interface. '
                f'({self.page_size} > {self.max_page_size})'
            ) 
開發者ID:Gorialis,項目名稱:jishaku,代碼行數:29,代碼來源:paginators.py

示例10: roles

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def roles(self, ctx: CommandContext):
        guild: Guild = ctx.guild
        paginator = Paginator()
        for role in guild.roles:
            paginator.add_line(role.name + ' ' + str(role.id))

        for page in paginator.pages:
            await ctx.send(
                embed=Embed(
                    color=Color.blurple(),
                    description=page)) 
開發者ID:BaseChip,項目名稱:RulesBot,代碼行數:13,代碼來源:info.py

示例11: codeblock

# 需要導入模塊: from discord.ext import commands [as 別名]
# 或者: from discord.ext.commands import Paginator [as 別名]
def codeblock(contents, syntax="py"):
    """Returns a list of codeblock text for the given content.

    Content is broken into items with a character limitation to avoid
    going above single-message limits.
    """
    paginator = commands.Paginator(
        prefix='```{}'.format(syntax), max_size=2000)
    for line in contents.split('\n'):
        for wrapline in textwrap.wrap(line, width=1990):
            paginator.add_line(wrapline.rstrip().replace('`', '\u200b`'))
    return paginator.pages 
開發者ID:shibdib,項目名稱:Firetail,代碼行數:14,代碼來源:dev_cog.py


注:本文中的discord.ext.commands.Paginator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。