Skip to content

Direct messages

A bot can talk to a member privately, in a direct message (DM): a channel only the bot and that member can see. Not the owner, not administrators. The host relays it like any channel, so it is as private as the rest of the community: it never leaves the host, and no third party gets it.

A DM is always between one bot and one member; members don’t DM each other through the host.

  • The dms capability in its manifest, granted by the owner. The operator can forbid it for the whole host with [bots] allow_dms = false. Members see “can send direct messages” on the bot card.
  • events = ["dms"] (or *) to hear DMs opening and closing, and messages to hear what members write in them. A DM to the bot always arrives whole, even without message_content.
zaun-bot.toml
events = ["dms", "messages"]
[capabilities]
dms = true
// From any event listener:
const { channelId, messageId } = ctx.dm(memberId, 'Hi! Your report was received.');
// From a command, to the person who used it:
bot.messages.dm(interaction.member.memberId, { content: 'Here are your details', embeds: [details] });
interaction.reply({ content: 'Check your direct messages.', ephemeral: true });
// Lower level:
const dm = bot.dms.open(memberId); // the DM channel, opened if needed
bot.dms.listOpen(); // the bot's open DMs
bot.dms.close(dm.channelId);

A refusal (the member turned DMs from bots off) throws ZaunError with code: 'FORBIDDEN' and detail: 'dms_closed'.

dm opens the DM when there is none, then sends. Replies, reactions, embeds, components and modals all work in a DM, and so do the bot’s own slash commands (only that bot’s commands work there). Message events in a DM are marked (message.isDM in TypeScript, is_dm in Rust).

  • A member can turn DMs from bots off, per community. Then a bot can’t open a new DM with them: the call fails with FORBIDDEN and reason dms_closed. Handle it; it isn’t an error in your bot.
  • A member can close a DM. Until they open it again (or write in it), the bot can’t write into it (dms_closed).
  • Members can open a DM with a bot themselves, if the bot has dms.

In apps, members do this with zaun-client: member.dm(), channel.closeDm() and community.setDmsFromBots(false).

  • A bot opens at most 10 new DMs per minute.
  • Into a DM the member has never written in, a bot writes at most 5 messages per hour. Once the member writes (or uses a command or button there), the limit lifts.
  • Beyond either: RATE_LIMITED with category dms and a retry time.

Answers to interactions are never limited this way: the member asked.

See the welcome DM example: it greets new members by DM, answers what they write back, and offers /dm-me.