Event Dispatchers
Event Dispatchers are used to send out events in the web client so that plugins can hook into these events and possibly process the event.
Example:
// on message SEND event
EventDispatcher.on("messageSend", async(payload) => {
let {message, channelType} = payload;
if(channelType === "discord_text"){
let sendingResult = await sendDiscordMessage(message)
}
})Available events
infiniteScrollDescription: When the chat is scrolled all the way to the top Data:
{
element,
channelType: await getCurrentChannelType(),
channelId: UserManager.getChannel()
}messageSendDescription: When a user is sending a message, but before it is sent to the server. Channel types other than text are not sent to the server. Data:
{
message: msgPayload,
channelType,
}getChannelTree_finishDescription: After the entire channel tree was rendered. Data: none
messageCreateDescription: New incoming message received. Data:
{
message
}getChatLogDescription: When the chat log requests starts Data:
{
container, // element where the chat messages will be inserted into
index, // timestamp filter for messages in the past. (createdAt < index)
appendTop, // for infinite scroll. if messages are inserted above
channelId,
channelType: await getCurrentChannelType(channelId),
firstElement: refElement, // first message element if chat; can be null
preventDispatch // prevent endless loops
}getChatLog_finishDescription: After the chat log was fetched and inserted Data:
{
container,
index,
appendTop,
channelId,
channelType: await getCurrentChannelType(channelId),
firstElement: refElement,
preventDispatch
}getMemberList Description: When the member list is being loaded but before its being displayed. Additionally, Data:
{
members, // object of all members that will be potentially listed
channelId
}TIP
You can modify members and these changes will be reflected in the member list!
Example:
// only show dcts users in the list and ignore 3rd party integrations
EventDispatcher.on("getMemberList", async (data) => {
data.members = Object.fromEntries(
Object.entries(data.members).filter(([id, member]) => {
return member?.type === null
})
);
});