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.
wilt avatar
wilt
emailToDiscordWebhook
Script
Email to Discord Forwarder Usage First, create a Discord Webhook and add it to your Val.town environment variables . Then create an Email Val: import { getEmailHandler } from "https://esm.town/v/wilt/emailToDiscordWebhook?v=19"; // e.g. ["email@example.com", "otherEmail.address.biz"] const senderAllowlist = JSON.parse(Deno.env.get("DISCORD_EMAIL_ALLOWLIST") || "[\"*\"]"); const webhookUrl = Deno.env.get("MY_DISCORD_WEBHOOK")!; export default getEmailHandler({ replyToSender: false, senderAllowlist, webhookUrl, }); Now, whenever you send an email to your email val, it will be forwarded to your Discord webhook
0
nate avatar
nate
handleDiscordInteraction
HTTP
Forked from xi8s/handleDiscordInteraction
0
Danster21 avatar
Danster21
registerDiscordSlashCommandWithOptions
Script
Forked from neverstew/registerDiscordSlashCommand
0
wilt avatar
wilt
handleDiscordInteraction
HTTP
Forked from maxm/discordBotExample
0
lgug2z avatar
lgug2z
kofiDiscordNotification
HTTP
Forked from lgug2z/stripeSubscriptionDiscordNotification
0
stevekrouse avatar
stevekrouse
discordWebhook
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
1
dglazkov avatar
dglazkov
discordBot
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, });
2
mattx avatar
mattx
verify_discord_signature
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.
1
maxm avatar
maxm
discordBotExample
HTTP
An interactive, runnable TypeScript val by maxm
0
artivilla avatar
artivilla
slothdaobot
HTTP
SlothDAObot Allow your discord guild to run the following actions in their own channels: /links --2 to print a list of links in the last 2 weeks /summary --2 to print a summary of all the content shared in the last 2 weeks How to deploy Create a new discord bot new appplication: https://discord.com/developers/applications Under applications > OAuth2 , header OAuth2 URL Generator , select Bot Under Bot Permissions , select all options that are relevant (see example for this bot below) Copy Generated URL from the bottom of the page and open and install for your guild/community. Note, the permissions are not saved on the page upon refreashing the page.
0
jkoster avatar
jkoster
discordBot
Script
Forked from dglazkov/discordBot
0
xi8s avatar
xi8s
handleDiscordInteraction
HTTP
disco bot
0
vtdocs avatar
vtdocs
discordSendDM
Script
An interactive, runnable TypeScript val by vtdocs
1
Curt avatar
Curt
discord
Script
An interactive, runnable TypeScript val by Curt
0
glommer avatar
glommer
DiscordNotifier
Cron
An interactive, runnable TypeScript val by glommer
0
malloc avatar
malloc
register_discord_commands
Script
Forked from mattx/register_discord_commands
0