Skip to content

Client

Client

Represents a client for interacting with the Discord API.

Parameters:

Name Type Description Default
token str

The token of the bot.

required
application_id int

The ID of the application that the bot is associated with.

required
public_key str

The public key of the application.

required

Attributes:

Name Type Description
http HttpClient

The HTTP client that will be used to make requests to Discord.

Source code in dismake/client.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
class Client:
    """Represents a client for interacting with the Discord API.

    Parameters
    -----------
    token: str
        The token of the bot.
    application_id: int
        The ID of the application that the bot is associated with.
    public_key: str
        The public key of the application.

    Attributes
    ----------
    http: HttpClient
        The HTTP client that will be used to make requests to Discord.
    """

    def __init__(
        self,
        token: str,
        application_id: int,
        public_key: str,
    ) -> None:
        self.http: HttpClient = HttpClient(token=token, application_id=application_id)
        self._verify_key = VerifyKey(key=bytes.fromhex(public_key))
        self.__events: Dict[str, List[AsyncFunction]] = {}

    def verify(self, signature: str, timestamp: str, body: bytes) -> bool:
        """Verify the incoming signature from Discord.

        Parameters
        ----------
        signature: str
            The signature from Discord.
        timestamp: str
            The timestamp from Discord.
        body: bytes
            The body of the request from Discord.

        Returns
        -------
        bool
            True if the signature is valid, False otherwise.
        """
        try:
            self._verify_key.verify(
                smessage=timestamp.encode() + body, signature=bytes.fromhex(signature)
            )
        except BadSignatureError:
            return False
        else:
            return True

    async def parse_interaction_create(self, data: InteractionData) -> None:
        """Parse and execute the appropriate action for an incoming interaction.

        Parameters
        ----------
        data: InteractionData
            The incoming interaction data.
        """
        interaction = Interaction(client=self, data=data)

        if interaction.is_application_command:
            ...
        if interaction.is_message_component:
            ...
        if interaction.is_modal_submit:
            ...

parse_interaction_create async

parse_interaction_create(data: InteractionData) -> None

Parse and execute the appropriate action for an incoming interaction.

Parameters:

Name Type Description Default
data InteractionData

The incoming interaction data.

required
Source code in dismake/client.py
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
async def parse_interaction_create(self, data: InteractionData) -> None:
    """Parse and execute the appropriate action for an incoming interaction.

    Parameters
    ----------
    data: InteractionData
        The incoming interaction data.
    """
    interaction = Interaction(client=self, data=data)

    if interaction.is_application_command:
        ...
    if interaction.is_message_component:
        ...
    if interaction.is_modal_submit:
        ...

verify

verify(signature: str, timestamp: str, body: bytes) -> bool

Verify the incoming signature from Discord.

Parameters:

Name Type Description Default
signature str

The signature from Discord.

required
timestamp str

The timestamp from Discord.

required
body bytes

The body of the request from Discord.

required

Returns:

Type Description
bool

True if the signature is valid, False otherwise.

Source code in dismake/client.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
def verify(self, signature: str, timestamp: str, body: bytes) -> bool:
    """Verify the incoming signature from Discord.

    Parameters
    ----------
    signature: str
        The signature from Discord.
    timestamp: str
        The timestamp from Discord.
    body: bytes
        The body of the request from Discord.

    Returns
    -------
    bool
        True if the signature is valid, False otherwise.
    """
    try:
        self._verify_key.verify(
            smessage=timestamp.encode() + body, signature=bytes.fromhex(signature)
        )
    except BadSignatureError:
        return False
    else:
        return True