A Golang package that provides an easy way to create serverless Discord slash command applications
go get github.com/wafer-bw/disgoslash
The following guide shows how to use disgoslash
with Vercel serverless functions to execute and respond to a Discord slash command.
This guide does not cover using environment variables, GitHub secrets, or Vercel secrets. Instead, secrets are used directly within the example code to keep it simpler. Please only use the credentials of the new application created while following this guide. When you are finished with the guide, delete the application and create a new one and employ environment variables and/or secrets within your code to protect your application secrets.
- Log into your Discord account and create a new server.
- Enable "Developer Mode" in your Discord App Settings under "Appearance".
- In the new server you created, right click on it's name and click on "Copy ID", this is your
Guild ID
.
- Create a new application here.
- On this page you will find both the
Client ID
andPublic Key
.- These two secrets should not be tracked in version control
- Within the application you created above, click on "Bot" in the left pane.
- Click on "Add Bot".
- On this page you will find the bot's
Token
.- This secret should not be tracked in version control
- Within the application you created above, click on "OAuth2" in the left pane.
- Under "Scopes" check "applications.commands"
- Copy the URL in the textbox and go to that URL in a new browser window/tab
- In the "Add to Server" dropdown select the server you created above.
The following secrets you have collected above should not be tracked in version control:
Client ID
Public Key
Token
- Open examples/vercel/api/index.go
- Fill in the secrets from above by making the following replacements
CLIENT_ID
-> Your applicationClient ID
PUBLIC_KEY
-> Your applicationPublic Key
TOKEN
-> Your applicationToken
GUILD_ID
-> Your serverGuild ID
- Ensure you are in the examples/vercel directory here
- Deploy to vercel
vercel #> Vercel CLI 21.3.3 #> ? Set up and deploy “~/disgoslash/examples/vercel”? [Y/n] y #> ? Which scope do you want to deploy to? Your Name #> ? Link to existing project? [y/N] n #> ? What’s your project’s name? hellotest #> ? In which directory is your code located? ./ #> No framework detected. Default Project Settings: #> - Build Command: `npm run vercel-build` or `npm run build` #> - Output Directory: `public` if it exists, or `.` #> - Development Command: None #> ? Want to override the settings? [y/N] n #> 🔗 Linked to yourusername/hellotest (created .vercel and added it to .gitignore) #> 🔍 Inspect: https://vercel.com/yourusername/hellotest/adshjfkdashjfdsal [1s] #> ✅ Production: https://hellotest-tau.vercel.app [copied to clipboard] [45s] #> 📝 Deployed to production. Run `vercel --prod` to overwrite later (https://vercel.link/2F). #> 💡 To change the domain or build command, go to https://vercel.com/yourusername/hellotest/settings
- Copy the "Production" URL from the output of running
vercel
. - On your Discord application's General Information page set the "Interactions Endpoint URL" to the URL you copied above, adding
/api
to the end.https://hellotest-tau.vercel.app/api
- After saving those changes you should see a green bar with a message like "All your edits have been carefully recorded."
- Change into the
sync
directorycd sync
- Run sync
go run sync.go #> Collecting outdated commands... #> Guild: GLOBAL #> success #> Guild: 000000000000000000 #> success #> Unregistering outdated commands... #> Guild: GLOBAL, Command: hello #> success #> Registering new commands... #> Guild: 000000000000000000, Command: hello #> success #> Guild: GLOBAL, Command: hello #> success
In your discord server type /hello
, press tab, enter a name, then hit enter. The command should run and the bot should respond.
/hello name: Bob
#> Hello Bob!
- Stable release version
- Internal client does not have an Edit method, it only uses Discord's create and delete endpoints right now
- Support for syncing application command permissions
- Some models in ./discord are not translated to Go structs yet
- Exporter to export ApplicationCommands to JSON files
- CLI tool to list, delete, create, update application commands