Classes

Hoshimi

Class representing the Hoshimi manager.

Signature

export declare class Hoshimi extends TypedEmitter<HoshimiEvents>

Private types

JSDoc

Examples

import { Hoshimi, SearchSources } from "hoshimi";

const manager = new Hoshimi({ // or via createHoshimi() function
 sendPayload: async (guildId, payload) => {
     const guild = await <Client>.guilds.fetch(guildId);
     if (!guild) return;

     await guild.shard.send(payload); // Adjust this line based on your library's method to send payloads
 },
	nodes: [
		{
			host: "localhost",
			port: 2333,
         password: "youshallnotpass",
			secure: false,
		},
    ],
});

manager.on("nodeReady", (node) => console.log(`Node ${node.id} is ready.`));
manager.on("playerCreate", (player) => console.log(`Player created for guild ${player.guildId}.`));
manager.on("error", (error) => console.error("An error occurred:", error));

<Client>.on("ready", () => {
  manager.init({ id: <Client>.user.id, username: <Client>.user.username });
});

console.log(manager); // The manager instance
@classHoshimi@extendsTypedEmitter<HoshimiEvents> *

Properties

readonly players: Collection<string, PlayerStructure>;

The players for the manager.

@type{Collection<string, PlayerStructure>}@readonly
ready: boolean;

If the manager is ready.

@type{boolean}

Methods

isUsable(): boolean;

Check if the manager is usable.

Returns

If the manager is usable.

Examples

if (manager.isUsable()) {
	console.log("The manager is usable.");
} else {
	console.log("The manager is not usable.");
}
isUseable(): boolean;

Check if the manager is usable.

Deprecated

Use {@link Hoshimi.isUsable } instead. This misspelled alias will be removed in a future release.

Returns

If the manager is usable.

debug(level: DebugLevels, message: string): void;

Emit a debug event.

Parameters

level
The debug level.
message
The debug message.

Returns

Examples

manager.debug(DebugLevels.Manager, "This is a debug message.");
getPlayer(guildId: string): PlayerStructure | undefined;

Get the player for the guild.

Parameters

guildId
The guild id to get the player.

Returns

The player for the guild.

Examples

const player = manager.getPlayer(guildId);
if (player) {
	console.log(`The player for ${guildId} is ${player}`);
} else {
	console.log(`The player for ${guildId} is not found.`);
}
deletePlayer(guildId: string): boolean;

Delete the player for the guild.

Parameters

guildId
The guild id to delete the player.

Returns

If the player was deleted.

Examples

const player = manager.deletePlayer(guildId);
if (player) {
	console.log(`The player for ${guildId} was deleted.`);
} else {
	console.log(`The player for ${guildId} was not found.`);
}
updateVoiceState(packet: GatewayPackets): Promise<void>;

Handle the raw packet for voice state and voice server updates.

Parameters

packet
The packet to handle

Returns

Examples

client.on("raw", (packet) => manager.updateVoiceState(packet));
init(info: ClientInfo): void;

Initialize the manager.

Parameters

info
The client data to use.

Returns

Examples

manager.init({
	id: "clientId",
	username: "clientUsername",
});
createPlayer(options: PlayerOptions): PlayerStructure;

Create a new player.

Parameters

options
The options for the player.

Returns

The created player.

Examples

const player = manager.createPlayer({
	guildId: "guildId",
	voiceId: "voiceId",
});

console.log(player); // The created player

player.connect();
player.play(track);