Twitch
Types
TwitchUser
Represents a user on Twitch
Property | Type | Description |
---|---|---|
id | string | ID of the user |
name | string | Name of the user (Username) |
displayName | string | Display name of the user |
profileImageUrl | string | URL of the user profile image |
TwitchFollower
Represents a user following a channel on Twitch
Property | Type | Description |
---|---|---|
id | string | ID of the user |
name | string | Name of the user (Username) |
displayName | string | Display name of the user |
followedAt | Date | Date that the user started following |
Functions
sendChat
Function (message: string) => Promise<void>
Sends a chat message to twitch chat
Argument | Type | Example | Description |
---|---|---|---|
message | string | ”Example message” | The message to send to twitch chat |
const message = "This message will be sent to twitch chat";
// Use "await" to wait for the message to send before continuingawait api.twitch.sendChat(message);
sendChatAnnouncement
Function (message: string) => Promise<void>
Sends a chat message to twitch chat
Argument | Type | Example | Description |
---|---|---|---|
message | string | ”Example message” | The message to send to twitch chat |
color Optional | string | ”blue”, “green”, “orange”, “purple”, “primary” | Color of the announcement message |
const message = "This message will be sent to twitch chat as an announcement";
// Use "await" to wait for the message to send before continuingawait api.twitch.sendChatAnnouncement(message, "primary");
getUserByUsername
Function (username: string) => Promise<TwitchUser | null>
Attempts to lookup a twitch user by username returns a TwitchUser if one is found otherwise
returns null
Argument | Type | Example | Description |
---|---|---|---|
username | string | ”twitch” | The username of the user to lookup |
const username = "twitch";const user = await api.twitch.getUserByUsername(username);
if (user === null) { await api.twitch.sendChat("User not found"); return;}
console.log(user);
shoutout
Function (shoutout: string) => Promise<void>
Triggers a twitch shoutout for the provided user
Argument | Type | Example | Description |
---|---|---|---|
userId | string | The ID of the user to shoutout |
const userId = "/* some ID */";
// Use "await" to wait for the shoutout to completeawait api.twitch.shoutout(userId);
isModerator
Function (userId: string) => Promise<boolean>
Checks if the user with the provided ID is a moderator
Argument | Type | Example | Description |
---|---|---|---|
userId | string | The ID of the user to check moderator status of |
const userId = "/* some ID */";const isModerator = await api.twitch.isModerator(userId);
if (isModerator) { return "That user is a moderator";} else { return "That user is not a moderator";}
isVip
Function (userId: string) => Promise<boolean>
Checks if the user with the provided ID is a vip
Argument | Type | Example | Description |
---|---|---|---|
userId | string | The ID of the user to check vip status of |
const userId = "/* some ID */";const isVip = await api.twitch.isVip(userId);
if (isVip) { return "That user is a vip";} else { return "That user is not a vip";}
isFollower
Function (userId: string) => Promise<boolean>
Checks if the user with the provided ID is a follower
Argument | Type | Example | Description |
---|---|---|---|
userId | string | The ID of the user to check following status of |
const userId = "/* some ID */";const isFollower = await api.twitch.isFollower(userId);
if (isFollower) { return "That user is a vip";} else { return "That user is not a vip";}
getFollower
Function (userId: string) => Promise<TwitchFollower | null>
Get a follower of the channel by user ID will return a TwitchFollower if the user is following otherwise will return null
Argument | Type | Example | Description |
---|---|---|---|
username | string | ”twitch” | The username of the user to lookup |
const userId = "/* some ID */";const follower = await api.twitch.getFollower(userId);
if (follower === null) { await api.twitch.sendChat("User is not following"); return;}
console.log(follower);
getUsernameArg
Function
(rawArg: unknown, validate: boolean = false) => string | null
Attempts to extract a username from the provided argument.
Normalizes the username into a format without @ and without any leading or trailing whitespace, optionally validating that the username is a valid twitch username.
Argument | Type | Example | Description |
---|---|---|---|
username | string | ”twitch” | The username to parse |
validate Optional | boolean | true / false | When enabled the username will be checked ensuring its a valid username |
const usernameArg = "@TestUser ";const username = api.twitch.getUsernameArg(usernameArg);
console.log(username); // "TestUser"
Invalid username (With validate set to true, unknown symbols will cause null):
const usernameArg = "@&$__";const username = api.twitch.getUsernameArg(usernameArg);
console.log(username); // null
isValidUsernameStrict
Function (username: string) => boolean
Validates that the provided username is a valid twitch username. Ensuring that the characters within the username are allowed and that the username is within the expected length requirements
Argument | Type | Example | Description |
---|---|---|---|
username | string | ”twitch” | The username to validate |
Valid username:
const usernameArg = "TestUser";const username = api.twitch.isValidUsernameStrict(usernameArg);
console.log(username); // true
Invalid username:
const usernameArg = "&$__";const username = api.twitch.isValidUsernameStrict(usernameArg);
console.log(username); // false
deleteChatMessage
Function (messageId: string) => Promise<void>
Deletes a chat message by ID
Argument | Type | Example | Description |
---|---|---|---|
messageId | string | The ID of the chat message to delete |
const messageId = "/* some ID */";
// "await" to wait until the message is deletedawait api.twitch.deleteChatMessage(messageId);
deleteAllChatMessages
Function () => Promise<void>
Deletes all messages in the chat (Same as the /clear chat command)
// "await" to wait until the chat is clearedawait api.twitch.deleteAllChatMessages();
createStreamMarker
Function (description?: string) => Promise<void>
Create a new stream marker
Argument | Type | Example | Description |
---|---|---|---|
description Optional | string | ”Something happened” | Optional description for the marker |
// "await" to wait until the marker is createdawait api.twitch.createStreamMarker("Something happened");