How can I send this list as one message in discord.py?

moinierer3000

I just tried adding a listrole command on my discord bot which lists every user with a certain role. However I can't seem to find a solution where my bot sends the whole list as one single message, it sends out every single member in the list as one message, which gets annoying with a large amount of members.

Here's my code so far:

@bot.command()
@commands.has_permissions(administrator=True)
async def listrole(ctx, role:discord.Role):
    members = role.members
    if len(members) > 100:
        await ctx.send("Too many members to list")
    else:
        for member in members:
            memberlist = ''.join(f"{member.display_name}#{member.discriminator}")
            await ctx.send(memberlist)

Help is greatly appreciated, I'm very new to Python in general

Random Davis

Define your memberlist before the loop, and append to it. Then, join all the items in that list into one long string separated by newlines, and send it after the loop completes:

memberlist = []
for member in members:
    memberlist.append(f"{member.display_name}#{member.discriminator}")
await ctx.send('\n'.join(memberlist))

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

how can i make my discord.py bot send a message i choose to a channel i choose?

분류에서Dev

(discord.py) How can I get a list of how many permissions a user has

분류에서Dev

How can i error handle the spotify command in discord.py?

분류에서Dev

Can I send a message through a network?

분류에서Dev

How can I send a list of array to parse and retrieve it and show it in a UItableView?

분류에서Dev

How can I read all pages of an API response using aiohttp with discord.py?

분류에서Dev

Discord py message.createdat

분류에서Dev

discord.py message.channel.send가 작동하지 않습니다.

분류에서Dev

Python discord Bot coping message from one user and send them in a webhook

분류에서Dev

Is it possible that I can convert simple string to SOAP Message and send it?

분류에서Dev

How can I realize that android send one string to a php page and obtain a JSON array?

분류에서Dev

message.channel.id Discord PY

분류에서Dev

Send Discord Message from a looped function

분류에서Dev

Discord.py: How to go through channel history and search for a specific message?

분류에서Dev

How could i make a command to send a specific message to a specific person?

분류에서Dev

how can I design custom toast message?

분류에서Dev

discord.py rewrite on_message not existing command

분류에서Dev

Discord.py AttributeError: type object 'Context' has no attribute 'message'

분류에서Dev

How can send a list/vector/array of dataframes to a function in R

분류에서Dev

How can I serve a static page from urls.py?

분류에서Dev

How to Send list of data from one activity to another one activity in android

분류에서Dev

How to get tag of user in discord.py?

분류에서Dev

How can I send notifications/alerts using the linux terminal?

분류에서Dev

how can i use function in $message statement in the following code

분류에서Dev

How can I emit message in panel's onMessage method?

분류에서Dev

How can I create a message box from the command line?

분류에서Dev

How can I programmatically determine the time a Gmail label was applied to a message?

분류에서Dev

How can I print out session message in Laravel?

분류에서Dev

How can I get rid of the message "kvm: disabled by BIOS"?

Related 관련 기사

  1. 1

    how can i make my discord.py bot send a message i choose to a channel i choose?

  2. 2

    (discord.py) How can I get a list of how many permissions a user has

  3. 3

    How can i error handle the spotify command in discord.py?

  4. 4

    Can I send a message through a network?

  5. 5

    How can I send a list of array to parse and retrieve it and show it in a UItableView?

  6. 6

    How can I read all pages of an API response using aiohttp with discord.py?

  7. 7

    Discord py message.createdat

  8. 8

    discord.py message.channel.send가 작동하지 않습니다.

  9. 9

    Python discord Bot coping message from one user and send them in a webhook

  10. 10

    Is it possible that I can convert simple string to SOAP Message and send it?

  11. 11

    How can I realize that android send one string to a php page and obtain a JSON array?

  12. 12

    message.channel.id Discord PY

  13. 13

    Send Discord Message from a looped function

  14. 14

    Discord.py: How to go through channel history and search for a specific message?

  15. 15

    How could i make a command to send a specific message to a specific person?

  16. 16

    how can I design custom toast message?

  17. 17

    discord.py rewrite on_message not existing command

  18. 18

    Discord.py AttributeError: type object 'Context' has no attribute 'message'

  19. 19

    How can send a list/vector/array of dataframes to a function in R

  20. 20

    How can I serve a static page from urls.py?

  21. 21

    How to Send list of data from one activity to another one activity in android

  22. 22

    How to get tag of user in discord.py?

  23. 23

    How can I send notifications/alerts using the linux terminal?

  24. 24

    how can i use function in $message statement in the following code

  25. 25

    How can I emit message in panel's onMessage method?

  26. 26

    How can I create a message box from the command line?

  27. 27

    How can I programmatically determine the time a Gmail label was applied to a message?

  28. 28

    How can I print out session message in Laravel?

  29. 29

    How can I get rid of the message "kvm: disabled by BIOS"?

뜨겁다태그

보관