discord application command in cf workers
-
Create a discord application in https://canary.discord.com/developers/applications. If you already have an application that you can use to test, no need to create new
-
Add this application to a test server using this link: https://canary.discord.com/api/oauth2/authorize?client_id=<application_id>&scope=applications.commands. Replace <application_id> with your application's app id, which you can find in the General Information tab of your application. (Remove the angle brackets as well while replacing <application_id>)
-
Create a
.env
file in the root of the project -
Go to the OAuth2 page of the app
-
Put
CLIENT_ID
andCLIENT_SECRET
from the OAuth2 page in the.env
file as shown in the example. (These are used to exchange for a token (see this), which is used only to register commands, for example, see this) -
Put the discord guild id as
SERVER_ID
as well, in the.env
file -
Now run
npm run init
. This will register the two test commands (tag
andcreate
in init/createGuildCommand.js). The commands will be created for the server only -
In a terminal,
cd
into the project, and runnpm ci
to install dependencies -
From your discord application's General Informations tab, grab the
PUBLIC KEY
, runnpm run put_public_key
, and when it asks to enter secret value, paste the public key there and enter -
Run
npm start
-
Open another terminal, change directory to the project, and run
npm run ngrok
-
Copy the ngrok url (https one)
-
Go to your applicataion in the discord applications page, paste the ngrok url in the
Interactions Endpoint URL
field and hit Save. Cross your fingers and wait for it to get the url accepted -
Test the
/tag
command in your test server