Introduction

Get started with C# code actions in Streamer.bot

CPHInline Class

CPH refers to the original development name of Streamer.bot, ChannelPointsHandler

When you add a new Execute C# Code sub-action, you will be greeted with the following code snippet:

using System;

public class CPHInline
{
    public bool Execute()
    {
        // your main code goes here
        return true;
    }
}
For every execute code sub-action, this is the minimum that must be present for it to function.

Within all C# code actions you have access to the CPH class, allowing you to make calls to internal Streamer.bot methods.

Explore all available C# methods at API References > C# Methods

Execute()

When your C# sub-action is executed, the Execute() method is always called.

This is where you should place your main code logic, as shown in the example below:

Example.cs
public bool Execute()
{
    CPH.LogInfo("Hello from C#");
    return true;
}

Normally this method returns true to allow execution of any subsequent sub-actions.

If for some reason you would like to cancel further execution, and skip any remaining sub-actions in the current action, you can return false.

Example.cs
public bool Execute()
{
  if (someCondition) {
    CPH.LogInfo("This action will now stop executing further sub-actions.");
    return false; // Stop execution of further sub-actions
  }

  return true; // Allow further execution
}

Custom Methods

You can also define your own custom methods within the CPHInline class, and call them from within the Execute() method.

Example.cs
public bool Execute()
{
    CPH.LogInfo("Starting execution...");
    CustomMethod();
    return true;
}

public void CustomMethod()
{
    CPH.LogInfo("Hello from a custom method!");
}

Video Tutorials

Explore some introductory video tutorials on using C# in Streamer.bot

C# Crash Course for Streamer.bot

by nutty

Streamer.bot C# Shorts

by TerrierDarts