 messages.

Registering a Discord Alerter in ZenMLNext, you need to register a discord alerter in ZenML and link it to the bot you just created. You can do this with the following command:

zenml alerter register discord_alerter \

--flavor=discord \

--discord_token=<DISCORD_TOKEN> \

--default_discord_channel_id=<DISCORD_CHANNEL_ID>

After you have registered the discord_alerter, you can add it to your stack like this:

zenml stack register ... -al discord_alerter

Here is where you can find the required parameters:

DISCORD_CHANNEL_ID

Open the discord server, then right-click on the text channel and click on the 'Copy Channel ID' option.

If you don't see any 'Copy Channel ID' option for your channel, go to "User Settings" > "Advanced" and make sure "Developer Mode" is active.

DISCORD_TOKEN

This is the Discord token of your bot. You can find the instructions on how to set up a bot, invite it to your channel, and find its token here.

When inviting the bot to your channel, make sure it has at least the following permissions:

Read Messages/View Channels

Send Messages

Send Messages in Threads

How to Use the Discord Alerter

After you have a DiscordAlerter configured in your stack, you can directly import the discord_alerter_post_step and discord_alerter_ask_step steps and use them in your pipelines.

Since these steps expect a string message as input (which needs to be the output of another step), you typically also need to define a dedicated formatter step that takes whatever data you want to communicate and generates the string message that the alerter should post.

As an example, adding discord_alerter_ask_step() to your pipeline could look like this:

from zenml.integrations.discord.steps.discord_alerter_ask_step import discord_alerter_ask_step

from zenml import step, pipeline

@step

def my_formatter_step(artifact_to_be_communicated) -> str:

return f"Here is my artifact {artifact_to_be_communicated}!"

@pipeline

def my_pipeline(...):

...

artifact_to_be_communicated = ...