Back to APIs list

Discord API examples & templates

Use these vals as a playground to view and fork Discord API examples and templates on Val Town. Run any example below or find templates that can be used as a pre-built solution.
camajudson avatar
handleDiscordInteraction
@camajudson
HTTP
Forked from maxm/discordBotExample
ktodaz avatar
sendDiscordMessage
@ktodaz
Script
Send Chunked Discord Message This function is used to send a message to a Discord webhook. If the message exceeds the maximum character limit (2000 characters), it will be divided into chunks and sent as multiple messages. Parameters message (string): The message to be sent to the Discord webhook. Return Value This function does not return any value. Example Usage: const message = "This is a long message that needs to be sent to Discord. It may exceed the character limit, so it will be divided into smaller chunks."; await @ktodaz.sendDiscordMessage(message); In the above example, the sendDiscordMessage function is used to send the message to the Discord webhook. If the message exceeds 2000 characters, it will be split into smaller chunks and sent as separate messages. Required Secrets: Ensure you have added the secret for discord_webhook in your val.town secrets settings (Profile -> Secrets)
stevekrouse avatar
discordWebhook
@stevekrouse
Script
Send a Discord message Send a message to a Discord channel from Val Town. It's useful for notifying your team or community when someone interesting happens, like a user signup, Stripe payment, mention on social media, etc. import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook"; await discordWebhook({ url: Deno.env.get("engDiscord"), content: "Hi from val town!", }); Example val: https://www.val.town/v/stevekrouse.discordWebhookEx Setup 1. Create a Discord Webhook Follow the instructions here: https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks It really only takes 2 minutes. 2. Copy webhook URL Paste it into your secrets as discordWebhook . 3. Send a message! import { discordWebhook } from "https://esm.town/v/stevekrouse/discordWebhook"; await discordWebhook({ url: Deno.env.get("engDiscord"), content: "Hi from val town!", }); Example val: https://www.val.town/v/stevekrouse.discordWebhookEx
stevekrouse avatar
sendDiscordMessage
@stevekrouse
Script
Forked from ktodaz/sendDiscordMessage
jkoster avatar
registerDiscordCommands
@jkoster
Script
Forked from mattx/register_discord_commands
mattx avatar
verify_discord_signature
@mattx
Script
verify_discord_signature Verify HTTP signatures coming from Discord. public_key should be the Ed25519 public key from Discord, as a hex string body should be the request body as a string. If you have a JSON object as the request body, use JSON.stringify. signature should be the X-Signature-Ed25519 header timestamp should be the X-Signature-Timestamp header You must return a 401 error and return early if this function returns false, otherwise you will pretty quickly get a big scary warning from Discord that your endpoint has been removed. Note that you'll only be able to add one once you've integrated this correctly. As this function only deals with strings, it doesn't matter whether you use an Express or web endpoint.
dglazkov avatar
discordBot
@dglazkov
Script
A simple Discord Bot scaffolding, a slight rev on the one in the valtown guide . The discordBot function takes in an object where each key is a Discord command and the value is a function to handle the command. If the function returns a Promise , it will be handled as a deferred interaction with a followup message . Usage: import { discordBot } from "https://esm.town/v/dglazkov/discordBot"; const echo = async (data) => { await new Promise((r) => setTimeout(r, 5000)); return { type: 4, data: { content: data.data.options[0].value, }, }; }; export default discordBot({ ping: () => ({ type: 4, data: { content: `Pong! It is ${new Date()}`, }, }) echo, });
augustveix avatar
discordBot
@augustveix
Script
Forked from dglazkov/discordBot
meglado avatar
lovelyBeigeSole
@meglado
Script
Forked from dglazkov/discordBot
jkoster avatar
discordBot
@jkoster
Script
Forked from dglazkov/discordBot
meglado avatar
discordBot
@meglado
Script
Forked from augustveix/discordBot
xi8s avatar
handleDiscordInteraction
@xi8s
HTTP
disco bot
Curt avatar
discord
@Curt
Script
An interactive, runnable TypeScript val by Curt
vtdocs avatar
discordSendDM
@vtdocs
Script
An interactive, runnable TypeScript val by vtdocs
maxm avatar
discordBotExample
@maxm
HTTP
An interactive, runnable TypeScript val by maxm
glommer avatar
DiscordNotifier
@glommer
Cron
An interactive, runnable TypeScript val by glommer