trixxy-stream
v1.0.0
Published
A package for TikTok and YouTube stream notifications.
Maintainers
Readme
trixxy-stream
A Discord.js package for sending TikTok and YouTube stream live notifications.
Installation
npm install trixxy-streamDependencies
This package relies on the following npm packages:
discord.jsaxioscheerioytsr(for YouTube stream checking)
Make sure these are installed in your project.
Usage
Here's how to use the TrixxyStreamNotifications class in your Discord bot:
const { Client, GatewayIntentBits } = require('discord.js');
const TrixxyStreamNotifications = require('trixxy-stream');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
const streamMonitor = new TrixxyStreamNotifications(client, 60000); // Check every 60 seconds
// Add a TikTok user to monitor (replace 'tiktokusername' and 'YOUR_DISCORD_CHANNEL_ID')
streamMonitor.addStream('tiktokusername', 'tiktok', 'YOUR_DISCORD_CHANNEL_ID');
// Add a YouTube channel to monitor (replace 'youtubechannelid' and 'YOUR_DISCORD_CHANNEL_ID')
// You can find YouTube channel IDs in the URL (e.g., youtube.com/channel/UC-lHJZR3Gqxm24_Vd_D_smQ)
streamMonitor.addStream('UC-lHJZR3Gqxm24_Vd_D_smQ', 'youtube', 'YOUR_DISCORD_CHANNEL_ID');
streamMonitor.startMonitoring();
});
client.login('YOUR_BOT_TOKEN');TrixxyStreamNotifications Class Methods
constructor(client, interval = 60000)
Initializes the stream notification monitor.
client: An instance ofdiscord.js.Client.interval: (Optional) The interval in milliseconds to check for stream status updates. Defaults to 60000 (1 minute).
addStream(userId, platform, discordChannelId)
Adds a stream to be monitored for live status.
userId: For TikTok, this is the username (e.g.,tiktokusername). For YouTube, this is the YouTube channel ID (e.g.,UC-lHJZR3Gqxm24_Vd_D_smQ).platform: The streaming platform. Must be either'tiktok'or'youtube'.discordChannelId: The ID of the Discord channel where notifications should be sent.
Throws: Error if an invalid platform is specified.
startMonitoring()
Starts the periodic checking of stream statuses. If monitoring is already running, it will do nothing.
stopMonitoring()
Stops the periodic checking of stream statuses. If monitoring is not running, it will do nothing.
checkStreams() (Private Method)
This method is called internally by startMonitoring at the specified interval. It checks the live status of all added streams and sends notifications if a stream goes live.
sendNotification(userId, platform, discordChannelId, title, url) (Private Method)
This method is called internally to send a Discord embed notification when a stream goes live.
Important Notes on TikTok Monitoring
Monitoring TikTok live streams reliably is challenging due to the lack of official public APIs for live status. The current implementation relies on web scraping, which is highly susceptible to breaking if TikTok changes its website structure. For a more robust solution, you might need to explore third-party services or unofficial APIs, which come with their own risks and limitations.
YouTube monitoring is more reliable due to better public data access, though still relies on ytsr for searching channel information.
