Squiso 是一款免费且功能强大的自动化工具,可让您使用简单的脚本自定义您的 Twitch 流。

如何在 Discord 上发布 Twitch 频道更新

每次您在 Twitch 上更新标题或类别时,此示例都会发送一条 Discord 消息。

脚本示例

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 { SquisoString oldTitle = new SquisoString(""); SquisoString oldCategoryName = new SquisoString(""); @Override public void onInitiated(API api) throws SquisoException { // Get the current channel information ChannelData channelData = api.getTwitchChannelData(); // Save the current title and category, so that we know if they get updated this.oldTitle = channelData.getTitle(); this.oldCategoryName = channelData.getCategoryName(); api.log("[Example_DiscordMessageTwitchCategoryName] Old title is \"" + oldTitle + "\"."); api.log("[Example_DiscordMessageTwitchCategoryName] Old category is \"" + oldCategoryName + "\"."); } @Override public void onTwitchChannelUpdate(OnTwitchChannelUpdateData data, API api) throws SquisoException { // Extract the current channel title and category SquisoString currentTitle = data.getTitle(); SquisoString currentCategoryName = data.getCategoryName(); api.log("[Example_DiscordMessageTwitchCategoryName] Title is \"" + data.getTitle() + "\"."); api.log("[Example_DiscordMessageTwitchCategoryName] Category is \"" + data.getCategoryName() + "\"."); // Start writing the Discord message SquisoString discordMessage = new SquisoString(""); // If the title was changed if (!currentTitle.equals(oldTitle)) { // Compose the discord message discordMessage.append("Squiso just updated their title:"); discordMessage.append("\n"); discordMessage.append("\n"); discordMessage.append("> " + currentTitle); discordMessage.append("\n"); discordMessage.append("\n"); discordMessage.append("https://www.twitch.tv/twitch"); // Save the new title oldTitle = currentTitle; } // If the category was changed if (!currentCategoryName.equals(oldCategoryName)) { // Compose the discord message discordMessage.append("Squiso just updated their category:"); discordMessage.append("\n"); discordMessage.append("\n"); discordMessage.append("> " + currentCategoryName); discordMessage.append("\n"); discordMessage.append("\n"); discordMessage.append("https://www.twitch.tv/twitch"); // Save the new category oldCategoryName = currentCategoryName; } // Assign the Discord webhook URL SquisoString discordWebhookURL = new SquisoString("https://discord.com/api/webhooks/123/abc"); // Send the Discord message api.sendSimpleDiscordMessage(discordWebhookURL, discordMessage); } }