Appearance
Class: SubGiftEvent
Represents a gift subscription on the channel: a viewer gifts one or more subs (Twitch channel.subscription.gift event).
Remarks
Handed to the callback of k.twitch.onSubGift. The event describes the gifter and how many subs were gifted (total), not each recipient. When the gift is anonymous, the gifter identity is not available and getGifter resolves to null.
Example
ts
k.twitch.onSubGift((event) => {
const who = event.isAnonymous() ? 'An anonymous viewer' : event.user_name;
k.chat.say(`${who} gifted ${event.total} sub(s)! 🎁`);
});Properties
broadcaster_user_id
ts
broadcaster_user_id: string;Twitch id of the broadcaster (the channel).
broadcaster_user_login
ts
broadcaster_user_login: string;Twitch login of the broadcaster.
broadcaster_user_name
ts
broadcaster_user_name: string;Twitch display name of the broadcaster.
cumulative_total
ts
cumulative_total: number;Total number of subs this gifter has ever gifted on the channel, or null if the gifter chose not to share it (or the gift is anonymous).
is_anonymous
ts
is_anonymous: boolean;Whether the gift was made anonymously.
received_at
ts
received_at: number;Timestamp (in milliseconds) at which the SDK received the event.
tier
ts
tier: string;Raw Twitch subscription tier of the gifted subs: "1000"/"2000"/"3000".
total
ts
total: number;Number of subscriptions gifted in this event.
user_id
ts
user_id: string;Twitch id of the gifter (empty/placeholder when anonymous).
user_login
ts
user_login: string;Twitch login of the gifter (empty when anonymous).
user_name
ts
user_name: string;Twitch display name of the gifter (empty when anonymous).
Methods
getCumulativeTotal()
ts
getCumulativeTotal(): number;Returns the gifter's all-time gifted total on the channel.
Returns
number
The cumulative total, or null if not shared/anonymous.
getGifter()
ts
getGifter(): Promise<User>;Resolves the full Kappapps viewer who gifted the subs.
Returns
Promise<User>
The matching User, or null if the gift is anonymous or the gifter is unknown to the platform.
Example
ts
k.twitch.onSubGift(async (event) => {
const gifter = await event.getGifter();
if (gifter) await gifter.addCurrency(event.total * 100);
});getTier()
ts
getTier(): 1 | 2 | 3;Returns the tier of the gifted subs as a number.
Returns
1 | 2 | 3
1, 2 or 3.
getTotal()
ts
getTotal(): number;Returns the number of subscriptions gifted in this event.
Returns
number
The gifted count.
isAnonymous()
ts
isAnonymous(): boolean;Indicates whether the gift was made anonymously.
Returns
boolean
true if anonymous.