Permission
torrent-client
permission is required.
{
//...
"plugin": {
"permissions": {
"scopes": ["torrent-client"],
}
}
}
Core Methods
getTorrents
Retrieves a list of all torrents in the torrent client.
Example:
// Get all torrents from the client
try {
const torrents = await ctx.torrentClient.getTorrents()
console.log("Retrieved torrents:", torrents)
} catch (error) {
console.error("Error getting torrents:", error)
}
getActiveTorrents
Retrieves a list of active torrents (downloading/uploading) from the torrent client.
Example:
// Get only active torrents
try {
const activeTorrents = await ctx.torrentClient.getActiveTorrents()
console.log("Active torrents:", activeTorrents)
} catch (error) {
console.error("Error getting active torrents:", error)
}
addMagnets
addMagnets(magnets, dest)
Adds magnet links to the torrent client.
Parameters:
magnets
: string[] - Array of magnet links
dest
: string - Destination path for downloaded files
Example:
// Add magnet links to the torrent client
try {
await ctx.torrentClient.addMagnets(
["magnet:?xt=urn:btih:xxxxxx", "magnet:?xt=urn:btih:yyyyyy"],
"/downloads/anime"
)
console.log("Magnets added successfully")
} catch (error) {
console.error("Error adding magnets:", error)
}
removeTorrents
removeTorrents(hashes)
Removes torrents from the client.
Parameters:
hashes
: string[] - Array of torrent hashes to remove
Example:
// Remove torrents from the client
try {
await ctx.torrentClient.removeTorrents(["abc123def456", "xyz789uvw"])
console.log("Torrents removed successfully")
} catch (error) {
console.error("Error removing torrents:", error)
}
pauseTorrents
pauseTorrents(hashes)
Pauses specified torrents.
Parameters:
hashes
: string[] - Array of torrent hashes to pause
Example:
// Pause specific torrents
try {
await ctx.torrentClient.pauseTorrents(["abc123def456", "xyz789uvw"])
console.log("Torrents paused successfully")
} catch (error) {
console.error("Error pausing torrents:", error)
}
resumeTorrents
resumeTorrents(hashes)
Resumes specified torrents.
Parameters:
hashes
: string[] - Array of torrent hashes to resume
Example:
// Resume specific torrents
try {
await ctx.torrentClient.resumeTorrents(["abc123def456", "xyz789uvw"])
console.log("Torrents resumed successfully")
} catch (error) {
console.error("Error resuming torrents:", error)
}
deselectFiles
deselectFiles(hash, indices)
Deselects specific files within a torrent.
Parameters:
hash
: string - Hash of the torrent
indices
: number[] - Array of file indices to deselect
Example:
// Deselect specific files in a torrent
try {
await ctx.torrentClient.deselectFiles("abc123def456", [0, 2, 5])
console.log("Files deselected successfully")
} catch (error) {
console.error("Error deselecting files:", error)
}
getFiles
Retrieves all files within a specific torrent.
Parameters:
hash
: string - Hash of the torrent
Example:
// Get all files in a torrent
try {
const files = await ctx.torrentClient.getFiles("abc123def456")
console.log("Torrent files:", files)
} catch (error) {
console.error("Error getting files:", error)
}