Basic Discord Bot Example
This is a fully customizable example Discord bot that you can add to your
Discord guild in just a few clicks. You don't need anything other than a Discord
account to get started! After forking and setting up this app, your bot will:
- Respond when it is tagged in a channel with a friendly, informational message.
- Respond to a Discord slash command
/member-count with the number of members in the guild.
The slash command requires a bit more setup after forking, but don't worry,
we'll walk through everything here! All behavior is completely customizable by
editing the app code.
Bot Mention Handler
The bot mention handler is relatively straightforward. You can find it under
functions/events/discord/bot_mention.js. After creating and naming your bot and linking
it to Autocode, you can tag it as shown below to see a message like the one below:
Member Count Command
Discord slash commands
are currently in open beta and can currently only be managed via API, which means
they require a bit more setup than the previous bot mention handler. Additionally,
Discord treats guild member related events and APIs as privileged, which means for
this specific command to work, you'll need to grant those privileges to your bot.
Registering a Slash Command
After following the instructions to link your newly created Discord bot and
forking this app, you'll need to register the slash command via an API request.
Fortunately, you can easily do this by navigating to
the create method on the discord/commands API docs page in Autocode
and taking advantage of the fact that you can make API calls from there.
After following the above link, set up the arguments to the API call like this:
For this bot, the
name parameter must be
member-count. We suggest creating the
command as a guild command
rather than a global one for this bot as global commands can take up to an hour
before they are visible, so you should also populate the
with the id of the guild you added your bot to during the Autocode linking
If you don't have your guild id handy, you can retrieve it by enabling
Developer Mode in your Discord user settings under the
Advanced section of
After enabling developer mode, right click your guild icon in the left sidebar of
the interface and select
Copy ID from the bottom of the menu, then paste it into
Authenticate and Link Accounts, link the same bot you linked
when forking this app, then press
Run to finish registering your command with Discord!
The final step to get this command working is to enable
Privileged Gateway Intents
for your bot. If you try to run your command before doing so, you'll see a message
To fix this, go to the
Discord developer portal and select
your bot out of the list to open your bot's settings. Press the
Bot tab, then
scroll down until you see a section like the one below:
Server Members Intent using the toggle — don't forget to press
Save Changes afterwards! Then, try running your command again and you
should something like this:
This will also enable you to receive
guild.member events for your bot, though
to get this working immediately you will need to update your bot's link to
Autocode by re-linking it as a new linked resource (pressing
Link New Resource and
pasting its information into the setup guide again).
If you have any questions or feedback, please join our community Slack channel
from the Community tab in the top bar. You can also follow us on Twitter, @AutocodeHQ.