Skip to content

Example gallery ​

The repository examples target Altkit Discord v4 and Node.js 20.19 or newer. Run them from the repository root after installing dependencies, or adapt one into an application that depends on @altkit/discord.

Use a non-critical account

Selfbot use violates Discord's Terms of Service and can result in account termination. Never put a real token in an example file, commit, issue, screenshot, or log.

Run an example ​

sh
git clone https://github.com/altkit/discord.git
cd discord
npm ci
cp .env.example .env

Populate only the variables needed by the selected example, then use Node's environment-file support:

sh
node --env-file=.env examples/Basic.js

Discord snowflake IDs should remain strings. Voice and media examples may also need codecs, native packages, files, or devices described in their headers.

Basics ​

Connect and respond ​

js
const { Client, Events } = require('@altkit/discord');

const client = new Client();

client.once(Events.ClientReady, readyClient => {
  console.log(`${readyClient.user.tag} is ready`);
});

client.on(Events.MessageCreate, async message => {
  if (message.author.id === client.user.id && message.content === '!ping') {
    await message.reply('Pong!');
  }
});

client.login(process.env.DISCORD_TOKEN);

Repository file: examples/Basic.js

Use an HTTP proxy ​

js
const client = new Client({
  http: {
    agent: process.env.HTTP_PROXY,
  },
});

Repository file: examples/Proxy.js

Messages ​

ExampleWhat it demonstratesEnvironment
ActivityMessage.jsSend a message activity payloadDISCORD_TOKEN, CHANNEL_ID
CreateAndVotePoll.jsCreate, vote on, and observe a pollDISCORD_TOKEN, CHANNEL_ID
VoiceMessage.jsSend prepared Ogg/Opus as a voice messageDISCORD_TOKEN, CHANNEL_ID
Embed.jsBuild the fork-specific hidden WebEmbed formatDISCORD_TOKEN
CaptchaSolver.jsSolve hCaptcha challenges through a serviceDISCORD_TOKEN, CAPSOLVER_API_KEY

Poll ​

js
const { Client, Events, Partials } = require('@altkit/discord');

const client = new Client({
  partials: [Partials.Message, Partials.Poll, Partials.PollAnswer],
});

client.once(Events.ClientReady, async readyClient => {
  const channel = await readyClient.channels.fetch(process.env.CHANNEL_ID);
  const message = await channel.send({
    poll: {
      question: { text: 'What is your favorite color?' },
      answers: [
        { text: 'Red', emoji: '🍎' },
        { text: 'Green', emoji: '🥗' },
        { text: 'Blue', emoji: '💙' },
      ],
      duration: 8,
      allowMultiselect: true,
    },
  });

  await message.vote(1, 3);
});

Account and application helpers ​

ExampleWhat it demonstratesEnvironment
JoinGuild.jsAccept an invite codeDISCORD_TOKEN, INVITE_CODE
AuthorizeUserApps.jsInstall a user applicationDISCORD_TOKEN, APPLICATION_ID
AddBot.jsAuthorize an application into a guildDISCORD_TOKEN, APPLICATION_ID, GUILD_ID; optional TOTP_SECRET
Slash commandsInvoke commands, upload attachments, and reply to modalsVaries by command

Treat invite, authorization, and verification flows as sensitive account operations. Use explicit IDs and inspect results instead of retrying failures indefinitely.

hCaptcha solving ​

When Discord requires an hCaptcha challenge, the REST handler calls ClientOptions.captchaSolver with the challenge payload and user agent, then replays the request with the solved token. examples/CaptchaSolver.js is a complete adapter that delegates solving to CapSolver:

js
const client = new Client({
  captchaRetryLimit: 2,
  captchaSolver: solveCaptcha, // see examples/CaptchaSolver.js
});

The callback must resolve to a non-empty token string. See client configuration → hCaptcha challenges for the full contract and trust-boundary notes.

Presence ​

RichPresence.js combines RichPresence, CustomStatus, and SpotifyRPC. SamsungRPC.js demonstrates a mobile-platform activity shape.

js
const custom = new CustomStatus(client).setEmoji('🛠️').setState('Building');

client.user.setPresence({ activities: [custom] });

See presence and activities for the concepts and caveats.

Voice and video ​

The examples/VoiceChannel/ directory includes join, audio playback, video playback, audio recording, and video recording examples. They are syntax-checked in CI but are not executed there because they require a live account, Discord resources, codecs, native packages, network access, and sometimes media devices.

Read voice and media before installing optional dependencies or recording participants.

Environment matrix ​

ExampleRequired values
Basic.js, Embed.js, RichPresence.js, SamsungRPC.jsDISCORD_TOKEN
CaptchaSolver.jsDISCORD_TOKEN, CAPSOLVER_API_KEY
ActivityMessage.js, CreateAndVotePoll.js, VoiceMessage.jsDISCORD_TOKEN, CHANNEL_ID
JoinGuild.jsDISCORD_TOKEN, INVITE_CODE
AuthorizeUserApps.jsDISCORD_TOKEN, APPLICATION_ID
AddBot.jsDISCORD_TOKEN, APPLICATION_ID, GUILD_ID; optional TOTP_SECRET
Proxy.jsDISCORD_TOKEN; optional HTTP_PROXY
VoiceChannel/*.jsDISCORD_TOKEN, VOICE_CHANNEL_ID, plus example-specific media requirements

Unofficial software. Not affiliated with or supported by Discord.