Client Object

Clients

Methods
class slack.Client(user_token: str, bot_token: str, token: Optional[str] = None, logger: Optional[Logger] = None, loop: Optional[AbstractEventLoop] = None, **options)

Create Client object from params. Represents a client connection that connects to Discord. This class is used to interact with the Discord WebSocket and API.

A number of options can be passed to the Client.

user_token

The your-self token. It must be start ‘xoxp-…’

Type:

str

bot_token

The bot token. It must be start ‘xoxb-…’

Type:

str

token

App-level token. It is startwith ‘xapp-…’

Changed in version 1.4.0: To optional.

Type:

Optional[str]

logger

Logger object.

New in version 1.4.0.

Type:

Optional[Logger.Logger]

loop

The asyncio.AbstractEventLoop to use for asynchronous operations. Defaults to None, in which case the default event loop is used via asyncio.get_event_loop().

Type:

Optional[asyncio.AbstractEventLoop]

@event
event is a decorator that takes a coroutine function and sets

it as an attribute of the class it’s decorating.

Parameters:

coro (Coro) – The coroutine function to be decorated.

Return type:

The coro function itself.

property channels: List[Channel]

List of channels.

Return type:

list[Channel]

await close() None

Close connection.

await connect(ws_url: str) None

connect to slack-API

Parameters:

ws_url (str) –

is_closed() bool

It returns a boolean value.

Returns:

The return value is a boolean value.

Return type:

bool

await login() None

Login as bot with websocket. Get teams, channels and member data.

property members: List[Member]

List of members.

Return type:

list[Member]

await on_error(event_name, exc: Exception, *args, **kwargs) None

It prints the name of the event that raised the exception, the name of the exception, and the name of the class that the event is in.

Parameters:
  • event_name – The name of the event that was raised.

  • exc (Exception) – The exception that was raised.

run() None

A blocking call that abstracts away the event loop initialisation from you. If you want more control over the event loop then this function should not be used. Use start() coroutine or connect() + login(). Roughly Equivalent to:

try:
    loop.run_until_complete(start(*args, **kwargs))
except KeyboardInterrupt:
    loop.run_until_complete(close())
    # cancel all tasks lingering
finally:
    loop.close()

Warning

This function must be the last function to call due to the fact that it is blocking. That means that registration of events or anything being called after this function call will not execute until it returns.

await start() None

start connection.

property teams: List[Team]

List of teams.

Return type:

list[Team]