Skip to content

Class: BoundPatcher ​

BoundPatcher is a utility class for modifying existing functions, with plugin scoping automatically supplied. An instance is available on instances of BdApi. This is extremely useful for modifying the internals of Discord by adjusting return values of React renders, or arguments of internal functions.

Methods ​

after() ​

after<M, K>(moduleToPatch, functionName, callback): (() => void) | null

This method patches onto another function, allowing your code to run afterwards. Using this, you are able to modify the return value after the original method is run.

Type Parameters ​

Type Parameter
M extends object
K extends string

Parameters ​

ParameterTypeDescription
moduleToPatchMObject with the function to be patched. Can also be an object's prototype.
functionNameKName of the function to be patched
callbackAsAfterCallback<M, K>Function to run after the original method. The function is given the this context, the arguments of the original function, and the return value of the original function.

Returns ​

(() => void) | null

Function that cancels the original patch


before() ​

before<M, K>(moduleToPatch, functionName, callback): (() => void) | null

This method patches onto another function, allowing your code to run beforehand. Using this, you are also able to modify the incoming arguments before the original method is run.

Type Parameters ​

Type Parameter
M extends object
K extends string

Parameters ​

ParameterTypeDescription
moduleToPatchMObject with the function to be patched. Can also be an object's prototype.
functionNameKName of the function to be patched
callbackAsBeforeCallback<M, K>Function to run before the original method. The function is given the this context and the arguments of the original function.

Returns ​

(() => void) | null

Function that cancels the original patch


getPatchesByCaller() ​

getPatchesByCaller(): GenericChildPatch[]

Returns all patches by this bound api. The patches all have an unpatch() method.

Returns ​

GenericChildPatch[]

Array of all the patch objects


instead() ​

instead<M, K>(moduleToPatch, functionName, callback): (() => void) | null

This method patches onto another function, allowing your code to run instead. Using this, you are able to replace the original completely. You can still call the original manually if needed.

Type Parameters ​

Type Parameter
M extends object
K extends string

Parameters ​

ParameterTypeDescription
moduleToPatchMObject with the function to be patched. Can also be an object's prototype.
functionNameKName of the function to be patched
callbackAsInsteadCallback<M, K>Function to run before the original method. The function is given the this context, arguments of the original function, and also the original function.

Returns ​

(() => void) | null

Function that cancels the original patch


unpatchAll() ​

unpatchAll(): void

Automatically cancels all patches created by this bound api

Returns ​

void