Skip to content

Struct EventContext

zaun_bot::EventContext · Struct

pub struct EventContext { … }

What an event handler can do: send, reply, react, delete and send direct messages. Every call is an ordinary command on the bot’s member, checked by the host.

Who and where the bot is, once on_ready has run (always, for every later event).

pub fn send<impl Into<Reply>>(&self, channel_id: &str, reply: impl Into<Reply>) -> Result<Id, HostError>

Sends a message to a channel. Returns its id.

The host’s refusal.

pub fn reply_to<impl Into<Reply>>(&self, message: &Message, reply: impl Into<Reply>) -> Result<Id, HostError>

Replies to a message, in its channel.

The host’s refusal.

pub fn react(&self, message: &Message, emoji: &str) -> Result<(), HostError>

Adds a reaction.

The host’s refusal.

pub fn delete_message(&self, message: &Message) -> Result<(), HostError>

Deletes a message (the bot’s own, or any with MANAGE_MESSAGES).

The host’s refusal.

pub fn dm<impl Into<Reply>>(&self, member_id: &str, reply: impl Into<Reply>) -> Result<(Id, Id), HostError>

Sends a direct message to a member (capability dms). Returns the DM’s channel id and the message id. FORBIDDEN with reason dms_closed when the member does not take DMs from bots or closed this one.

The host’s refusal.

pub fn is_me(&self, member_id: &str) -> bool

Whether member_id is the bot itself (to ignore its own messages).

pub fn mentions_me(&self, message: &Message) -> bool

Whether message mentions the bot: by its member id, by @everyone, or by one of its roles. Only when the message names roles does it ask the host for the bot’s own roles (community::get_member); a refusal there counts as not mentioned.

Clone, Debug, Default

Full rustdoc page