Skip to main content

Patcher

Patcher is a utility class for modifying existing functions. Instance is accessible through the BdApi. This is extremely useful for modifying the internals of Discord by adjusting return value or React renders, or arguments of internal functions.

Properties

Methods

after

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.

ParameterTypeDescription
callerstringName of the caller of the patch function
moduleToPatchobjectObject with the function to be patched. Can also be an object's prototype.
functionNamestringName of the function to be patched
callbackfunctionFunction 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: function - Function that cancels the original patch


before

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.

ParameterTypeDescription
callerstringName of the caller of the patch function
moduleToPatchobjectObject with the function to be patched. Can also be an object's prototype.
functionNamestringName of the function to be patched
callbackfunctionFunction to run before the original method. The function is given the this context and the arguments of the original function.

Returns: function - Function that cancels the original patch


getPatchesByCaller

Returns all patches by a particular caller. The patches all have an unpatch() method.

ParameterTypeDescription
callerstringID of the original patches

Returns: Array.<function()> - Array of all the patch objects


instead

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.

ParameterTypeDescription
callerstringName of the caller of the patch function
moduleToPatchobjectObject with the function to be patched. Can also be an object's prototype.
functionNamestringName of the function to be patched
callbackfunctionFunction to run before the original method. The function is given the this context, arguments of the original function, and also the original function.

Returns: function - Function that cancels the original patch


unpatchAll

Automatically cancels all patches created with a specific ID.

ParameterTypeDescription
callerstringID of the original patches

Returns: void