How Can I Automatically Split A List Up Based On A Given Requirement?
On Discord, you can only have messages of character length 2000 or under. I am trying to append the server name, member amount and server ID for each server that the bot is in to a
Solution 1:
One you have the serverslist
, you can pass it to a function that builds < 2000 character pages
def paginate(lines, chars=2000):
size = 0
message = []
for line in lines:
if len(line) + size > chars:
yield message
message = []
size = 0
message.append(line)
size += len(line)
yield message
then in your command
for message in paginate(serverlist):
embed.description = ''.join(message)
await ctx.send(embed=embed)
Post a Comment for "How Can I Automatically Split A List Up Based On A Given Requirement?"