Skip to content

Twitch

Types

TwitchUser

Represents a user on Twitch

PropertyTypeDescription
idstringID of the user
namestringName of the user (Username)
displayNamestringDisplay name of the user
profileImageUrlstringURL of the user profile image

TwitchFollower

Represents a user following a channel on Twitch

PropertyTypeDescription
idstringID of the user
namestringName of the user (Username)
displayNamestringDisplay name of the user
followedAtDateDate that the user started following

Functions

sendChat

Function (message: string) => Promise<void>

Sends a chat message to twitch chat

ArgumentTypeExampleDescription
messagestring”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 continuing
await api.twitch.sendChat(message);

sendChatAnnouncement

Function (message: string) => Promise<void>

Sends a chat message to twitch chat

ArgumentTypeExampleDescription
messagestring”Example message”The message to send to twitch chat
color Optionalstring”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 continuing
await 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

ArgumentTypeExampleDescription
usernamestring”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

ArgumentTypeExampleDescription
userIdstringThe ID of the user to shoutout
const userId = "/* some ID */";
// Use "await" to wait for the shoutout to complete
await api.twitch.shoutout(userId);

isModerator

Function (userId: string) => Promise<boolean>

Checks if the user with the provided ID is a moderator

ArgumentTypeExampleDescription
userIdstringThe 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

ArgumentTypeExampleDescription
userIdstringThe 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

ArgumentTypeExampleDescription
userIdstringThe 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

ArgumentTypeExampleDescription
usernamestring”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.

ArgumentTypeExampleDescription
usernamestring”twitch”The username to parse
validate Optionalbooleantrue / falseWhen 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

ArgumentTypeExampleDescription
usernamestring”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

ArgumentTypeExampleDescription
messageIdstringThe ID of the chat message to delete
const messageId = "/* some ID */";
// "await" to wait until the message is deleted
await 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 cleared
await api.twitch.deleteAllChatMessages();

createStreamMarker

Function (description?: string) => Promise<void>

Create a new stream marker

ArgumentTypeExampleDescription
description Optionalstring”Something happened”Optional description for the marker
// "await" to wait until the marker is created
await api.twitch.createStreamMarker("Something happened");