Appearance
Class: UserItemService
Sub-service for managing a viewer's inventory (items): give an item, use it or remove it.
Remarks
Available everywhere via k.users.item. You never have to instantiate this service yourself — it is created by the SDK when the app/widget starts.
Items that are given (add) reference a channel item (channel_item_id), whereas the use/remove actions (use, remove) target an instance owned by the viewer (user_item_id).
Example
ts
// Give a viewer 2 copies of a channel item
await k.users.item.add('twitchdev', 42, 2);Methods
add()
ts
add(
login,
channel_item_id,
quantity?): Promise<void>;Gives an item to a viewer (adds it to their inventory).
Parameters
login
string
The viewer's login (Twitch username).
channel_item_id
number
The identifier of the channel item to grant.
quantity?
number = 1
Number of copies to give.
Returns
Promise<void>
A promise resolved once the operation has been sent to the backend.
Default Value
1
remove()
ts
remove(login, user_item_id): Promise<void>;Removes an item from a viewer's inventory.
Parameters
login
string
The viewer's login (Twitch username).
user_item_id
number
The identifier of the item instance to remove.
Returns
Promise<void>
A promise resolved once the operation has been sent to the backend.
use()
ts
use(
login,
user_item_id,
args?): Promise<void>;Uses an item owned by a viewer.
Parameters
login
string
The viewer's login (Twitch username).
user_item_id
number
The identifier of the item instance owned by the viewer.
args?
string = ""
Optional arguments passed to the item when it is used.
Returns
Promise<void>
A promise resolved once the operation has been sent to the backend.
Default Value
""