DiscordWebhook
Posts messages from your plugin to a Discord webhook, for example a loot or level-up channel.
Final classRLPlugins API
public final class DiscordWebhookThis is the only way a plugin can send anything out.
Sending never blocks: the message goes out on another thread, so it is safe to call from a game event. send only tells you whether the message was accepted for sending. Your plugin never sees Discord's answer.
Limits, per plugin: 5 messages at once, then one every 2 seconds. A message over the limit is dropped and send returns false. Text longer than Discord allows is cut off. Messages never ping anyone: @everyone, role and user mentions show as plain text.
Tell players what your plugin posts and give them a setting to turn it off. Never post a login name, email, password or bank PIN.
Example
import com.tonic.api.webhook.DiscordWebhook;
import com.tonic.api.webhook.WebhookEmbed;
import com.tonic.api.webhook.WebhookMessage;
import net.runelite.api.ChatMessageType;
import net.runelite.api.events.ChatMessage;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@PluginDescriptor(name = "Clue Loot Poster")
public final class ClueLootPlugin extends Plugin {
// Paste your own webhook URL: channel settings, Integrations, Webhooks, Copy Webhook URL.
private static final String URL = "https://discord.com/api/webhooks/123456789012345678/your-webhook-token-goes-here-0000";
private DiscordWebhook webhook;
@Override
protected void startUp() {
webhook = DiscordWebhook.of(this, URL);
}
@Subscribe
public void onChatMessage(ChatMessage event) {
String text = event.getMessage();
if (event.getType() == ChatMessageType.GAMEMESSAGE && text.contains("Your clue is worth")) {
webhook.send(new WebhookMessage().embed(new WebhookEmbed()
.title("Clue done")
.description(text)
.color(0xFFAA00)
.timestamp(System.currentTimeMillis())));
}
}
}Members
Methods
- booleanisValid(String)
True when the text is a Discord webhook URL that
ofaccepts. - DiscordWebhookof(Plugin, String)
A webhook your plugin can post to.
- booleansend(String)
Posts plain text, at most 2000 characters.
- booleansend(WebhookMessage)
Posts a message with text, embeds or both.
isValid(String)static
public static boolean isValid(String url)True when the text is a Discord webhook URL that of accepts.
Parameters
url- Url.
of(Plugin, String)static
public static DiscordWebhook of(Plugin plugin, String url)A webhook your plugin can post to.
Pass the plugin itself and the webhook URL from Discord (channel settings, Integrations, Webhooks, Copy Webhook URL): DiscordWebhook.of(this, url). To post in a thread or forum post, add ?thread_id= and the thread's id to the URL. Throws IllegalArgumentException when the URL is not a Discord webhook URL; check a URL a player typed with isValid first.
Parameters
plugin- Plugin.
url- Url.
send(String)
public boolean send(String text)Posts plain text, at most 2000 characters.
Returns true when the message was accepted for sending, false when it is empty or your plugin is over its limit.
Parameters
text- Text.
send(WebhookMessage)
public boolean send(WebhookMessage message)Posts a message with text, embeds or both.
Returns true when the message was accepted for sending, false when it is empty or your plugin is over its limit.
Parameters
message- Message.
Also allowed
Every class has these, as in plain Java.
equals, toString