コード例 #1
0
    async def random(self, ctx):
        reload = '🔄'
        close = '❌'

        async def make_request():
            return {
                'mock': 'json',
                'request': 'data',
                'random_data': randint(1, 100)
            }

        async def update_data(menu):
            if menu.button_pressed(reload):
                response = await make_request()

                p = Page(title='Awesome Data',
                         description='We can reload this data.')
                p.add_field(name='Random Updating Integer',
                            value=response.get('random_data'))
                await menu.output.edit(embed=p.as_safe_embed())

            elif menu.button_pressed(close):
                await menu.close()

        page1 = Page(title='Example', description='example')
        page1.on_next(update_data)
        page1.buttons([reload, close])

        menu = ButtonMenu(ctx)
        menu.add_pages([page1])
        await menu.open()
コード例 #2
0
ファイル: poll_example.py プロジェクト: robertwayne/dpymenus
    async def poll(self, ctx):
        first = Page(title='Sun vs Moon Poll',
                     description='Do you prefer the sun or the moon?')
        first.set_footer(
            text='Only vote once! Your vote won\'t count if you cheat!')
        first.buttons(['\U00002600', '\U0001F315'])
        first.on_next(self.finish)

        second = Page(title='Sun vs Moon Poll', description=f'Results are in!')

        menu = Poll(ctx).set_timeout(10).add_pages([first, second])
        await menu.open()
コード例 #3
0
    async def text(self, ctx):

        page1 = Page(
            title='Ping Menu',
            description='Are you absolutely sure you want to send a ping command?',
        )
        page1.set_footer(text='Type `yes` if you are sure.\nType `quit` to cancel this menu.')
        page1.on_next(self.confirm)

        page2 = Page(title='Ping Menu', description='Pong!')

        menu = TextMenu(ctx)
        menu.add_pages([page1, page2])
        menu.normalize_responses()
        await menu.open()