- Installation
- Quick Start
- Chat System
- Webhook Events
- Channel Management
- Category System
- User Management
- Error Handling
- TypeScript Support
- Examples
npm install @botk4cp3r/kick.jsapi
# or
yarn add @botk4cp3r/kick.js
# or
pnpm add @botk4cp3r/kick.js
const { KickClient } = require('@botk4cp3r/kick.js');
// Create client instance
const client = new KickClient({
token: 'your-api-token',
webhookPort: 3000,
webhookPath: '/webhook',
webhookBaseUrl: 'http://your-domain.com'
});
// Start webhook server and subscribe to events
async function init() {
await client.startWebhookServer();
// Subscribe to all available events
await client.subscribeToEvents([
'chat.message.sent',
'channel.followed',
'channel.subscription.new',
'channel.subscription.renewal',
'channel.subscription.gifts'
]);
console.log('Bot is ready!');
}
// Listen for events
client.on('chatMessage', message => {
console.log(`${message.sender.username}: ${message.content}`);
});
client.on('channelFollowed', data => {
console.log(`New follower: ${data.follower.username}!`);
});
client.on('subscriptionNew', data => {
console.log(`New sub: ${data.subscriber.username}!`);
});
// Send a chat message
await client.sendChatMessage({
content: 'Hello World!',
type: 'bot'
});
init().catch(console.error);
// Simple bot message
await client.sendChatMessage({
content: 'Hello from bot!',
type: 'bot'
});
// Simple user message
await client.sendChatMessage({
content: 'Hello! Kappa',
type: 'user',
broadcasterUserId: '123456'
});
// New messages
client.on('chatMessage', msg => {
console.log(`${msg.sender.username}: ${msg.content}`);
// Auto-respond to commands
if (msg.content === '!ping') {
client.sendChatMessage({
content: 'Pong! ๐',
type: 'bot'
});
}
});
const client = new KickClient({
token: 'your-api-token',
webhookPort: 3000,
webhookPath: '/webhook',
webhookBaseUrl: 'http://your-domain.com'
});
await client.startWebhookServer();
// Subscribe to specific events
await client.subscribeToEvents([
'chat.message.sent',
'channel.followed',
'subscription.new',
'channel.subscription.renewal',
'channel.subscription.gifts'
]);
// Listen for events
client.on('channelFollowed', data => {
console.log(`New follower: ${data.follower.username}`);
});
client.on('subscriptionNew', data => {
console.log(`New sub: ${data.subscriber.username}`);
});
client.on('chatMessage', async (message) => {
// Command system example
const commands = {
'!ping': () => 'Pong! ๐',
'!discord': () => 'Join our Discord: discord.gg/example'
};
const command = message.content.toLowerCase();
if (commands[command]) {
await client.sendChatMessage({
content: commands[command](),
type: 'bot'
});
}
});
const AVAILABLE_EVENTS = {
'chat.message.sent', // New chat messages
'channel.followed', // When someone follows the channel
'channel.subscription.renewal', // Subscription renewals
'channel.subscription.gifts', // Gifted subscriptions
'channel.subscription.new' // New subscriptions
};
// Get current subscriptions
const currentSubs = await client.getEventSubscriptions();
console.log('Current subscriptions:', currentSubs);
// Subscribe to specific events
const subscription = await client.subscribeToEvents([
'chat.message.sent',
'channel.followed'
]);
// Subscribe with custom webhook method
const webhookSub = await client.subscribeToEvents([
'channel.subscription.new',
'channel.subscription.gifts'
]);
// Unsubscribe from events
await client.unsubscribeFromEvents(['subscription-id-1', 'subscription-id-2']);
// Validate incoming webhook
const isValid = await client.validateWebhook(headers, rawBody);
if (isValid) {
console.log('Valid webhook event!');
}
const client = new KickClient({
token: 'your-api-token',
webhookPort: 3000,
webhookPath: '/webhook',
webhookBaseUrl: 'https://your-domain.com'
});
// Start webhook server
await client.startWebhookServer();
// Subscribe to multiple events
await client.subscribeToEvents([
'chat.message.sent',
'channel.followed',
'subscription.new',
'subscription.renewal',
'subscription.gifts'
]);
// Handle different events
client.on('chatMessage', msg => {
console.log(`Chat: ${msg.sender.username}: ${msg.content}`);
});
client.on('channelFollowed', data => {
console.log(`New follower: ${data.follower.username}`);
});
client.on('subscriptionNew', sub => {
console.log(`New sub: ${sub.subscriber.username}`);
});
client.on('subscriptionRenewal', renewal => {
console.log(`Renewal: ${renewal.subscriber.username}`);
});
client.on('subscriptionGifts', gifts => {
console.log(`${gifts.gifter.username} gifted ${gifts.giftees.length} subs!`);
});
// Error handling
client.on('error', error => {
console.error('Subscription error:', error);
});
{
eventType: 'chat.message.sent',
payload: {
messageId: '123456',
content: 'Hello world!',
sender: {
id: '789',
username: 'username',
displayName: 'Display Name'
},
emotes: [
{
id: '123',
name: 'Kappa',
position: { start: 6, end: 11 }
}
]
}
}
{
eventType: 'channel.followed',
payload: {
broadcaster: {
id: '123',
username: 'broadcaster'
},
follower: {
id: '456',
username: 'follower'
}
}
}
{
eventType: 'subscription.new',
payload: {
broadcaster: {
id: '123',
username: 'broadcaster'
},
subscriber: {
id: '456',
username: 'subscriber'
},
tier: 1,
months: 1
}
}
// Get single channel
const channel = await client.getChannels(['123456']);
// Get multiple channels
const channels = await client.getChannels(['123', '456', '789']);
// Update stream title and category
await client.updateChannel({
categoryId: '123',
streamTitle: '๐ด New Stream Title!'
});
// Update just title
await client.updateChannel({
streamTitle: '๐ด Playing Games!'
});
// Search all categories
const allCategories = await client.searchCategories();
// Search specific game
const gaming = await client.searchCategories('Minecraft');
// Get category by ID
const category = await client.getCategory('123');
// Get single user
const user = await client.getUsers(['123456']);
// Get multiple users
const users = await client.getUsers(['123', '456', '789']);
try {
await client.sendChatMessage({
content: 'Test message'
});
} catch (error) {
if (error instanceof UnauthorizedError) {
console.error('Token is invalid or expired');
} else if (error instanceof ForbiddenError) {
console.error('Insufficient permissions');
} else if (error instanceof RateLimitError) {
console.error(`Rate limited. Try again in ${error.retryAfter} seconds`);
} else {
console.error('Unknown error:', error.message);
}
}
import {
KickClient,
ChatMessageOptions,
ChannelUpdateOptions,
WebhookEventType
} from '@botk4cp3r/kick.js';
// Client with typed options
const client = new KickClient({
token: string,
webhookPort: number,
webhookPath: string,
webhookBaseUrl: string
});
// Typed message options
const messageOptions: ChatMessageOptions = {
content: string,
type: 'bot' | 'user',
broadcasterUserId?: string
};
// Typed event handlers
client.on('chatMessage', (message: ChatMessage) => {
console.log(message.content);
});
const { KickClient } = require('@botk4cp3r/kick.js');
const client = new KickClient({
token: 'your-api-token',
webhookPort: 3000,
webhookPath: '/webhook',
webhookBaseUrl: 'http://your-domain.com'
});
const commands = {
'!help': 'Available commands: !help, !ping',
'!ping': 'Pong! ๐'
};
async function startBot() {
try {
// Start webhook server
await client.startWebhookServer();
// Subscribe to events
await client.subscribeToEvents([
'chat.message.sent',
'channel.followed',
'channel.subscription.new',
'channel.subscription.renewal',
'channel.subscription.gifts'
]);
console.log('Bot started and subscribed to events!');
} catch (error) {
console.error('Failed to start bot:', error);
process.exit(1);
}
}
// Chat command handler
client.on('chatMessage', async (message) => {
const command = message.content.toLowerCase();
if (commands[command]) {
await client.sendChatMessage({
content: commands[command],
type: 'bot'
});
}
});
// Event handlers
client.on('channelFollowed', async (data) => {
await client.sendChatMessage({
content: `Thanks for following, ${data.follower.username}! ๐`,
type: 'bot'
});
});
client.on('subscriptionNew', async (data) => {
await client.sendChatMessage({
content: `Welcome to the team, ${data.subscriber.username}! ๐`,
type: 'bot'
});
});
client.on('subscriptionRenewal', async (data) => {
await client.sendChatMessage({
content: `Thanks for resubbing, ${data.subscriber.username}! ๐`,
type: 'bot'
});
});
client.on('subscriptionGifts', async (data) => {
await client.sendChatMessage({
content: `Thanks ${data.gifter.username} for gifting ${data.giftees.length} subs! ๐`,
type: 'bot'
});
});
startBot().catch(console.error);