This sample demonstrates using Mongoose to build a sample Discord bot.
Make sure you have a local Stargate instance running as described on the main page of this repo.
Due to Discord dependencies, this sample app requires Node >= 18.
- Create a
.env
file with the keys from.env.example
and the values from the developer portal and your Discord server.* - Run
npm install
- Run
npm run seed
to create the Bot collection in Astra - Run
node ./deploy-commands.js
- Run
node ./index.js
DISCORD_GUILD_ID
: go into your server's settings and click on "Widget". The "Server ID" is theguildId
. See screenshot 1 below.DISCORD_CLIENT_ID
: go to the Discord developer portal, click your bot, and then click "OAuth2". The "Application ID" is theclientId
. See screenshot 2 below.DISCORD_TOKEN
: go to the Discord developer portal. Navigate to OAuth2 -> URL Generator", select 'bot' in the SCOPES and 'Use Slash Commands' in the 'BOT PERMISSIONS' section. Copy the URL that is generated, go to the URL on a new tab, and authorize as required. Then go back to the Discord developer portal, click on your bot under "My Applications", click on the "Bot" tab, and find the token under "Build-A-Bot". See screenshot 3 below.- Make sure to enable slash commands when selecting bot permissions.
For more information on setting up your bot and adding it to your server: https://discordjs.guide/preparations/setting-up-a-bot-application.html
Once the Discord bot is running, you should also see the bot "Online" in the Discord server's members list as shown in the following screenshot.
You should be able to execute the following commands in the "general" chat under "TEXT-CHANNELS"
/ping
: replies "Pong!"/count
: returns the number of documents currently in your local MongoDB collection./createdocument
: inserts a new document into your local MongoDB collection.
Below is a screenshot demonstrating executing each of the commands.
Anytime you add or update commands in the command folder, run step 3 again.