How GatewayBot works
masterA GatewayBot connects to Discord via the Gateway to receive real-time events. It is suitable for bots that need to react to various Discord events like messages, presence updates, or member changes.
Key Features:
- Event Listening: Use the
@bot.listen()decorator. Events are determined by the type annotation of the parameter or by passing the event type to the decorator. - Intents: By default,
GatewayBotenables all unprivileged intents. To enable all intents (including privileged ones like presence or message content), passintents=hikari.Intents.ALLto the constructor. - Event Filtering: You can filter events within your listener (e.g., checking
event.is_humanto ignore bots/webhooks).
import hikari
bot = hikari.GatewayBot(token="...")
@bot.listen()
async def ping(event: hikari.GuildMessageCreateEvent) -> None:
if not event.is_human:
return
me = bot.get_me()
if me.id in event.message.user_mentions_ids:
await event.message.respond("Pong!")
bot.run()