1. Create and install the application
Create an application in the developer console and save the bot token immediately. In the Bot tab, enable Public bot only if other people should be able to install it. Generate the invitation and select View channels, Send messages and Read message history. Choose a test community you manage, then authorize the installation.
Two identifiers are needed
Copy the destination channel ID from Lyra and keep it next to the bot token in environment variables. The token is secret; the channel ID is not.
2. Create the local project
This minimal example uses the Fetch API built into Node.js 18 and later, so it has no runtime dependency.
mkdir hello-lyra && cd hello-lyra
npm init -y
export LYRA_BOT_TOKEN="paste-the-token"
export LYRA_CHANNEL_ID="paste-the-channel-id"3. Send the first message
Save the file as index.mjs, then run node index.mjs. A 201 response creates the message. A 401 means the token is invalid; a 403 usually means the managed role is missing View channel or Send messages in that channel.
const api = 'https://beta.lyra.social/api/v1'
const token = process.env.LYRA_BOT_TOKEN
const channelId = process.env.LYRA_CHANNEL_ID
if (!token || !channelId) throw new Error('Missing Lyra environment variables')
const response = await fetch(`https://beta.lyra.social/api/v1/channels/${channelId}/messages`, {
method: 'POST',
headers: {
Authorization: `Bot ${token}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({ content: 'Hello from my first Lyra bot!' }),
})
const body = await response.json()
if (!response.ok) throw new Error(`${response.status}: ${body.error?.message}`)
console.log('Created message', body.id)4. Turn the script into a bot
- Use the official Node.js SDK when you want typed resource helpers and automatic Gateway resume
- Register a slash command from the Commands tab
- Subscribe only to the Gateway intents your bot actually needs
- Handle 429 with Retry-After and bounded retries
- Rotate the token immediately if it reaches a log, commit or screenshot