Macintosh Fan
Macintosh Fan

Reputation: 405

discord.py ClientConnectorError raise handling

I have the current code below:

try:
    client.run(token)
except:
    print("Connection error!")

There is one issue with this, a bare 'Except' is not a good idea. How do I type something like "Except ClientConnectorError:"?

Specific raise:

aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host discordapp.com:443 ssl:default [nodename nor servname provided, or not known]

Upvotes: 1

Views: 531

Answers (1)

Macintosh Fan
Macintosh Fan

Reputation: 405

I learned that you need to import the aiohttp module and use the class from there:

from aiohttp import connector

try:
    client.run(token)
except connector.ClientConnectorError:
    pass

You can of course do other actions instead of pass.

Upvotes: 1

Related Questions