Search code examples
pythonpython-3.xdiscorddiscord.py

discord.py question about message formatting codeblocks


Hello I have been wondering about few days cause I'm not that deep into python but how would one create this?

enter image description here

basically let's say you have a lits of 500 or more usernames and you want the output to be like that and of course there's a 2000 char limit and you'd need to do multiple separate codeblocks. My only concern is how?


Solution

  • In discord.py this is done with the help of the ext.command.Paginator class.

    Basically, it divides your text into several "pages" so you can send them in separate messages accounting for the Discord's message symbols limit.

    Example of a code would be:

    # somewhere in your command
    paginator = commands.Paginator(prefix='```python')
    paginator.add_line('some line')
    paginator.add_line('some other line')
    
    for page in paginator.pages:
        await ctx.send(page)