Skip to content

Latest commit

 

History

History

examples

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Examples

Welcome to the examples! The aim of these short snippets of code are to demonstrate some example usecases on how to use arc, and showcase the numerous features of the library.

Running examples

To run and test the examples, simply insert your token in into the constructor of hikari.GatewayBot(...)/hikari.RESTBot(...) by replacing the ..., then run the example using the following command:

python example_name.py

If you have any questions, or found an issue with one of the examples, feel free to open an issue, or join the hikari discord!

Gateway or REST?

Tip

If you're unsure which one to choose, it is recommended that you get started with a Gateway bot.

There are two main ways for a bot to connect to Discord & receive interactions, via either a GatewayBot or a RESTBot.

A bot connected to the Gateway needs to maintain a constant connection to Discord's servers through a WebSocket, and in turn receives events that inform it about things happening on Discord in real time (messages being sent, channels being created etc...). Interactions are also delivered to a bot of this type through the Gateway as events. In addition, Gateway bots typically have a cache and can manage complex state. This model is ideal for bots that need to do things other than just responding to slash commands, such as reading and responding to messages sent by users, or acting on other server events (e.g. a moderation bot).

A RESTBot however, isn't constantly connected to Discord, instead, you're expected to host a small HTTP server, and Discord will send interactions to your server by making HTTP POST requests to it. RESTBots only receive interactions from Discord, they do not receive events or other types of data. They are ideal for bots that manage little to no state, and rely only on users invoking the bot via slash commands. Setting up a RESTBot however is slightly more complicated compared to a GatewayBot, as it requires a publically accessible domain with TLS for Discord to be able to send interactions to your webserver.

Does this mean a Gateway bot cannot use the REST API?

No. Both Gateway & REST bots have access to the HTTP REST API Discord provides (see Client.rest), the primary difference between the two bot types is how Discord communicates with your bot, and what information it sends to it.