Squiso is a free, powerful automation tool that lets you customize your Twitch stream using simple scripts.

How to Create a Twitch !Clip Command With a Global Cooldown

This examples listens to the !clip chat message, creates a clip and then posts it to both Twitch chat and Discord, but also has a 2 minute global cooldown.

Script Example

import com.squiso.*; import com.squiso.exception.*; import com.squiso.scripting.*; import com.squiso.scripting.data.*; import com.squiso.keyboard.*; import com.squiso.twitch.*; import com.squiso.datatypes.*; import com.squiso.utils.*; // Important - Please do not change the row below - otherwise you will get a compilation error! public class Script_Example extends SquisoScript { // Create a variable that stores when the clip command was last used SquisoDate lastUsed = SquisoDate.nowLocal(); @Override public void onTwitchChatMessage(OnTwitchChatMessageData data, API api) throws SquisoException { // If the message text starts with !clip if (data.getMessageText().startsWith("!clip")) { // Save the time right now SquisoDate now = SquisoDate.nowLocal(); // Get the number of seconds between lastUsed and now SquisoInteger seconds = lastUsed.getSecondsSince(now); // If it is still within the 2 minute cooldown period if (seconds.isLessThan(120)) { api.log("Clip command still on cooldown: " + seconds); return; } // Set the lastUsed to now lastUsed = SquisoDate.nowLocal(); // Log that we are now creating a clip api.log("Will now try and create a Twitch clip!"); // Create a clip CreateTwitchClipResult createdClip = api.createTwitchClip(); // Specify 30 seconds (30*1000=30000 milliseconds) SquisoInteger waitTime = new SquisoInteger(10 * 1000); // Do this 30 seconds later (we wait 30 seconds to give Twitch time to generate an MP4 video out of the clip) api.doLater(waitTime, () -> { // Extract the clip ID to its own variable SquisoString clipID = createdClip.getClipID(); // Get additional data from the clip TwitchClip clip = api.getTwitchClip(clipID); // Send the message to Twitch chat SquisoString chatMessage = new SquisoString("A new clip was created: " + clip.getURL()); api.sendTwitchChatMessage(chatMessage); // Specify the Discord webhook URL SquisoString discordWebhook = new SquisoString("https://discord.com/api/webhooks/abc/123"); // Create the message that we will send to Discord SquisoString discordMessage = new SquisoString(""); discordMessage.append("A new clip was created by " + clip.getCreator() + "!"); discordMessage.append("\n"); discordMessage.append(clip.getURL()); // Send the message to the Discord channel api.sendSimpleDiscordMessage(discordWebhook, discordMessage); }); } } }