2

I have the following error when program ends.

Error:

RuntimeError: Event loop is closed

Code:

    client = discord.Client()
@client.event
async def on_ready():
    amount2 = 0
    for guild in client.guilds:
        for member in guild.members:
            members.insert(amount2, member)  # or do whatever you wish with the member detail
            amount2 = amount2 + 1
    await client.close()
client.run(TOKEN)

How can I resolve it?

4
  • 1
    await client.close() should be the reason why it's happening. Commented Aug 19, 2020 at 13:15
  • without that this code doesn't stop. All I need is to get members and stop this code to move forward Commented Aug 19, 2020 at 14:22
  • What do you mean it doesn't stop? the on_ready event is only ran once when the bot starts up. Commented Aug 19, 2020 at 15:18
  • 2
    I don't want bot to run all the time, I want it to only catch members and stop. Commented Aug 19, 2020 at 15:28

1 Answer 1

2

I got the same error and noticed it doesn't happen while debugging, so I added a sleep(1) after the close call:

await client.close()
time.sleep(1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.