meshcore.js
Guides

Post on a channel

Send a message on a channel from a command, within the radio's limits.

/announce Meeting at the clubhouse, 19:00 in a DM posts the text on the #club channel.

commands/announce.ts
export default new CommandBuilder()
  .setName('announce')
  .setDescription('Post on the club channel')
  .addStringArg((arg) => arg.setName('text').setRequired().setRest())
  .setHandler(async (ctx) => {
    const channel = ctx.client.channels.get('#club');
    if (!channel) return ctx.reply('#club is not on the radio');
    await channel.send(new MessageBuilder().setTitle('📣 Announcement').addLine(ctx.args.text).setOverflow('split'));
    return ctx.reply('Posted');
  });

What happens

client.channels.get() finds a channel by name or by slot index in the radio's table. The bot answers if the channel is missing instead of failing.

channel.send() accepts a string or a MessageBuilder. A plain string over the budget throws MessageTooLongError. The builder with setOverflow('split') sends up to three numbered parts instead.

The message goes through the send queue. Transmissions are two seconds apart and the parts of one message stay together.

Go further

On this page