PlayerData
export interface PlayerData {
[key: string]: unknown;
}
The data the bot keeps on a player with player.setData(), saved and restored with
it. Declare keys via module augmentation. getData(key) has no type parameter: declared keys read as their type or
undefined, undeclared keys as unknown. getData() without a key returns a copy. deleteData() and clearData()
remove keys from memory and from the next save. Every key is the bot's: the autoplay user is player.autoplayUser, the
now playing message player.nowPlayingMessage, and the skip flag is internal.
In 3.0.0, player.set() and player.get() are renamed setData() and getData(key), and player.delete() does not
exist: use deleteData().
declare module "magmastream" {
interface PlayerData {
djRole: string;
}
}
player.setData("djRole", "123"); // checked against PlayerData
const role = player.getData("djRole"); // string | undefined
const all = player.getData(); // a copy of every key
player.deleteData("djRole"); // true
Every key survives a restart as long as its value can be written as JSON. An object with a toJSON(), such as a
discord.js Message, is saved as what toJSON() returns, and a BigInt as a string. A key whose value cannot be
written (a circular object, a Map, a Set, a function) is the only one left out, with a Debug message that names it.
A bot key named like magmastream's old internal ones (skipFlag, nowPlayingMessage...) is kept.