Build a Discord command bot in minutes with Appwrite Cloud Functions
Tags: appwrite, discordcommandbot, appwritecloudfunctions
Published: 2023-11-29 10:42:20

If you’re a developer looking for a secure and efficient solution to build your Discord bots rapidly, then you’ve come to the right place. In this article, we’ll discuss an excellent tool that you can use to suit your needs called [Appwrite Functions](https://appwrite.io/docs/products/functions?utm_source=hackmamba&utm_medium=hackmamba-blog). 

Appwrite Functions is a feature provided by Appwrite that enables developers to create and automatically run custom backend code in response to events triggered by [Appwrite](https://appwrite.io/?utm_source=hackmamba&utm_medium=hackmamba-blog) or according to a predefined schedule. With Appwrite Functions, you can access several benefits, including scalability and enhanced security.

Why use a template for your Discord bots? Templates save time and effort by providing pre-built code for custom commands and features. Appwrite Functions offers a Discord command bot template, simplifying the development process. You can customize the template to meet your needs and seamlessly integrate unique functionalities.

This tutorial will walk you through the process of building your Discord command bot in minutes using Appwrite Functions.

So, without further ado, let's dive in!

## Prerequisites

Ensure that you have the following to follow along with the tutorial:

- An [Appwrite Cloud account](https://cloud.appwrite.io/?utm_source=hackmamba&utm_medium=hackmamba-blog)
- A [GitHub account](https://github.com/login)
- A [Server on Discord](https://support.discord.com/hc/en-us/articles/204849977-How-do-I-create-a-server-?utm_source=hackmamba&utm_medium=hackmamba-blog)
- A [2FA App](https://play.google.com/store/apps/details?id=com.twofasapp&hl=en&gl=US)

## Creating your Appwrite project

Log into your Appwrite Cloud account and create your Appwrite project to gain access to Appwrite's services. You’ll also gain access to your project ID and API key, which are required for using the Appwrite SDK. Set a name for your project, such as 'Discord Command Bot,' and then click the **Create Project** button:

![Creating your Appwrite Project](https://lh7-us.googleusercontent.com/BWgJdeFcoOJJ3SZ3b59_lHE0It57xHsi1GpM9IDIm35Mrem4CbTACBj4hVv_lEC5auGj7ixHpuJcrbTUzsNglTayGRMBqSccrBMmNupBCAKZFJiL-vIBPWgbgl2H8gvBLMX50GdanzuD3dnyK241RTY)



## Creating an Appwrite Function with the Discord command bot template

Here, we’ll easily create an Appwrite Function to automate your backend tasks and extend Appwrite with custom code.

Navigate to the side menu on your project dashboard and click on **Functions** to access the template:

![Opening Functions in Appwrite](https://lh7-us.googleusercontent.com/YgZspJEAIA55dXwRYAmZFubrBqWRMZXpmM8npoEtkT5CSzKtI-1IWWWOAOyTmA8UXJopP20GuH_8YzkwRr6p4_7jwY5D5xzw9e6CYKnkOKGoRRVjsQDjkH-VKmbFZrHVHHbG3eaHQueOq4GAflEE0yc)


Click on the **Templates** tab on the Functions page:

![Opening Templates](https://lh7-us.googleusercontent.com/fgnBEfy7J0q5XWh83uMX5yJbmBXvfs2Ixry4eGPR5XpfnqLSz7Pypw2avIVxI-Sjz5_ZovzErpqaVE17u-2ReQYjIUxqiHDzb7zlgzHIi1YGh2u3XWVwN6feq8xD1VxCm2yFEIK4DgBD9tpnl3CDw04)


Search for the **Discord Command Bot** template in the **Search templates** box as follows:

![](https://lh7-us.googleusercontent.com/3rq6Tn52_9zfHHhw-tJJeGoXzXJ3FU5W1dZAOZT82UcBD5idGsToRnpZ2vf2XjY2DUeWpPb5Yba1Zk4zPXwiFsRBkM8CCXRcPj2eyuJcm1oAO0pkKnOne4I1JLlcYSKVKpBfAG2Ea5pgPNREIUZcOqE)


Click the **Create function** button:

![](https://lh7-us.googleusercontent.com/CwXhRchbY-VVs6ephia5VEiT5cafaaFRSe9vwH9uPjTDOFLF0kGNUGodPuJbAjpbQDvGxbD3HvPl5XAMHoL4bb-ss94bEXsSgyFBjyLJMFkjKYwZjpcwzYVvVBQLApzvpfcXsgY5HleBi05P36D1NEc)


Select **Node.js-18.0** as the runtime for your discord command bot and click **Next**:

![](https://lh7-us.googleusercontent.com/awrjbrd6gwwd4Zo4ezWOPtHOgZkwL6Gwt5fPr0o71dYKBPEcgqJAiTGSROgpSEZIAEvlyv4ikgId6uje_it0Yjaq4KQqwWS2zBTkCCrG6vN7W7vPrhdh9EUj3VnacPZVF6CCu-UbHcR9i9zRVd28pQs)


Before you proceed, you’ll need to retrieve several values from your [Discord Developer](https://discord.com/developers/applications?utm_source=hackmamba&utm_medium=hackmamba-blog) [P](https://discord.com/developers/applications?utm_source=hackmamba&utm_medium=hackmamba-blog)[ortal](https://discord.com/developers/applications?utm_source=hackmamba&utm_medium=hackmamba-blog), namely the `public key`, `ID`, and `Bot token` of your application in your Discord Developer Portal. They will serve as the values for the environment variables passed to your function at runtime. 

On your Discord Developer Portal, click on **New Application**:

![](https://lh7-us.googleusercontent.com/vigr0ooggvngwrxajDUFbOUoElE4lbXoBxB9LgKNN8r_HrppPFDSpn011Zqy3mBFLVC350fVAVOzJ8NCvuj7gZXKeGkivZVuKqA1XBSF_P6RXQ_grx30nFvJkn8uCL1j9SzTyDqbR-LUcsvqYKyOrBM)


Enter the name of your application and click on the **Create** button:

![](https://lh7-us.googleusercontent.com/HQBX7kW8zF4MqfxXTwcUVGtLSsbazEKwOz1L-N5zokzn6FUJQK8A49hvBhnnnmFoNdjBoiPNT_Nxhok79q9i6Tq3Q8hOI4BAJJcCgSUbq18IxdihY3yhLaOC60KkO0Me1P-GpZ5WM6Ij9KedPuhPEvk)


Once you do that, your application ID and public key will be generated. Copy both of them:

![](https://lh7-us.googleusercontent.com/7TQ4Ejoh-JiuVSBOU8YZZ4RnXqn_oJ7Fo-xYC1T8Nx0FPABBzFjUNV8c_4Ub9en8w-eEkKOt4YC0K1kJSZ-XpmtskpX94rwWQG29zVCH6EdctZ-M0CaJk6Nydctbdx9dmZaD__r4ka_69ruEMHjIzd0)


Then, go back to your Functions in Appwrite and paste your copied `Application ID` and `Public key` as the values of your environment variables that will be passed to your function at runtime:

![](https://lh7-us.googleusercontent.com/5aIb-ssxPojozsgOFhDpBdzGJHsRmRTImnIblts4d6_tF1zYV1iNwECnBtFY8Rh8WzfS-d8CD7iZkOcTYBLzwGcMUIqOxO67OFIlWTv2sr1EUtlwOSc8BQr700szGSJ6l2x6zmcP_-rmhP7aZHZ_BPY)


Go back to your Discord Developer Portal to get your **DISCORD_TOKEN** variable, and on the slide menu, click on **Bot**, then click on the **Reset Token** button: 

![](https://lh7-us.googleusercontent.com/N8j7sZy2sVDfA7kFwNiqXnrgZxQSzqqopt3lwKDzvgqt1QqjoZ9ollChBZb_2yhG2tGTk_Qes-JiUZgK7iRjrDMwvkFUQKCrxWWEye_UcQrKDmYxJ8ugNLt2MjdZ2YYwZHC5Db5c8gviY51bSjrwIHI)


Once you do that, you’ll see the following message: click **Yes, do it!**

![](https://lh7-us.googleusercontent.com/pAWo_8DgKFhbGqJObemhiSWgog_3acuqD-1iCTYsaUlvbf-42nuas2ecHftGtU0pWWz9LQAIB-nx8HrhbZUFQ80LvOa8eJopwH-F5BvSGDYPZphAqL1BS66VCIxdg4lPV9-Rz_pF4lUS9ya-BOpDT1k)


Once you do that, you’ll get a 6-digit authentication code in your 2FA authentication app or whichever verification method you use. After entering the 2FA code, click on **Submit**:

![](https://lh7-us.googleusercontent.com/itKBB76ONDdP9Fp-EEdRyx5Qi6QcNj30e6gixkShpQvv0rz8DBoQ2-uKe8iG4IZEVIpUh8gi7csF0UXZsvKU3FdiWePc4PVgHHbb37rLSYwqVX_4t4QVJntDM9LgrwFqInSSELwIM-5WfCPFIQhDFC0)


 
Once you do that, your token will be generated. Click the **Copy** button to copy your token:

![](https://lh7-us.googleusercontent.com/LKC9bfq7Ihu2LQsyZOdVVKV-ijWWdgMmlwrbmk9ZeK4g1CuHlumV6UacwkHFEhaQ-XAuwzhOyZAQx9AdLOeB_YVssvBhAuM0n3Z7qtlBHPwSwuULIcMBCmDvYp0zOBvkA-JVe8QxtFe1mKo2nOyFRvg)


Go back to your Appwrite Functions, paste your copied token as the value for your **DISCORD_TOKEN** variable, and click the **Next** button:

![](https://lh7-us.googleusercontent.com/rkbYng6yCWJ9qc_6uJ88bMIIb45pH_VQjzu2cmbWc8mGm7xwqOQm0aR2mruco_GJF3WHl2O-WQSDynEh1sVF0pRG6X6UDvwdrywFCJFqwuwl-pC2TkDM9S1IxW78SbiRBGFAsDu7Mffeg6T10xcN2Ts)


This will take you to the next step of connecting your function to a new repository or an existing one within a selected Git organization. Select **Create a new repository** and click **Next**:

![](https://lh7-us.googleusercontent.com/5Ldo-urY1xgRxZEs2fvbct7imwnuBwD-EHk8ipFHxmAYWyrYki9vgqYyHrWOXyrZKT8RlTWEWLwnSbOrMaxj_kGQK--wxALjctVSNLYMhE5LNrhgYvgKWP7JfUDAcB3b6nHxRv81P30W5mFAGIJM0Zo)


You need to select a Git repository that will trigger your function deployments when updated. Choose GitHub from the options and click **Next**:

![](https://lh7-us.googleusercontent.com/vKYXDhUXdP9Re5aqHVMGinJbvukkDF2g8s6TVRDiyfCeA1KYBv0qyY61ag4X0pLMP6s2g0pFgWYmwyj-rnZLLEJe7hW2Dmzjg1EIq9NNbgOAGkMtUUCL9BjoC2tf_BVpy4somE7WYOEk11-bsbrRxQM)


Grant Appwrite permission to your GitHub account by clicking the **Install & Authorize** button:

![](https://lh7-us.googleusercontent.com/PgZ5VhMANCk1ymXgcmKMk-a55HrBdawT4aZVcOB_ibOXnQHnPeAm1gEw1UFowonGuyb6H8ZVPGIajiD-5CTtxN5uFVoud3T74TLKrZd_FPlb4muI03wZWd5Ipd4Wmh8gTycA3-0IXzsYLmODxQHRk24)


Once that is done, you will be redirected to Appwrite to continue your installation. Now that Appwrite has access to your GitHub, you can go back to choose the **Create a new repository** option, and this time, you will see the following:

![](https://lh7-us.googleusercontent.com/PIwy-SSMSPeRfVZ5s6Nd9TWLiFpGOK9JexkK1cDOWj_Z7X9hgxaXCkon31f4gkAiXyrbzAAiN4Vqynagcg_PGbztsXYs1INDE3QzSfeqmFH436j7cirT4lQwMALYHqo8I8ncdmaKr1JJ9p6wmQIE06I)


As you can see, a discord-command-bot repository has been automatically created for you. You can change the repository name if you so choose. You can leave your repository private and click **Next**. Afterward, your repository will be successfully created. 

Next, name your production branch or leave it as **main**, then click the **Create** button:

![](https://lh7-us.googleusercontent.com/jVkHtJxuJAZWgPUJhAR_IacISD1srsSpv8CR7v4NCFwDbAdZCjlX4nEuX509I582WzCxBm-Pl9iE8Wf9ESBf_WYH-k2dDIjpIEKJbWURu5W_k5_vifHAHRBBUu98lzPMINi0mFdtkj9lW8lV3JaS_gE)


Once you do that, you will see an alert saying that your Discord Command Bot has been created:

![](https://lh7-us.googleusercontent.com/ZivkpWUkVNPlecQ7v08boes2w1UuDdXf8y0vhPvVeZyNttU9YKz2-WAFJ3wih-3jCEiqDBqQVZZD84INg3wGzt6aIcg581F81MhOF2uehwpKwc8k_pbN_GasInprVN6ygRYF3wP65eSN4ycxMZWiKAo)


Your deployment will automatically display the deployment ID, build time, size, source, and link to your domains. Copy the link to your domains:

![](https://lh7-us.googleusercontent.com/FtJ7hXwdygrFTiX-mKHfp0sQI1iF6uSr_D-dSVRkrWlWn6M1jJjvNIDXXqgffIs1NJrU2AY8UBQj91MuF4k-UtdOysWPXZ9LyUg5oJI3Phw2wGJHF9j0l7cvZ8LasTsUgIz9F94RR9c0dUJMyL37fQQ)



## Configuring an interactions endpoint for your app

Go back to your Discord developer portal from your side menu, click on **General Information,** and scroll down to the **Interactions Endpoint URL** to configure an interactions endpoint to receive interactions via HTTP POSTs rather than over Gateway with a bot user:

![](https://lh7-us.googleusercontent.com/OS99XMTv23Ubw2nyGTNyExUhjAr25DkEF-YhZrgoj8ds25ZdbHFLm2TWQ538FlX51RUnPreTquQGKWDomBiBqeggzZE8iIA30esNGRD8_gs2cU8GrpcEFepFuR4sfOvDIf6sgzwRpvbqF0v9HadjTOQ)


Paste the link to your domains that you copied to configure an interactions endpoint by adding the `https://` in front of it and the “interactions” endpoint at the end. Your link should look like this: `https://``[your` `domains``]``/interactions.` Afterward, ensure that you save your changes by clicking the **Save Changes** button:

![](https://lh7-us.googleusercontent.com/PkHtVxWURz3PO2D5YXnqkneOfzzMG6S_-B4D6Z18mmW6CjpNe62VQRCF1JtDHTM3pP3uNxoJHarf9H2_DZUmBefLq0otxnwzClc6FTuSqF-JbDlnSOPgJa6kho2To9ALMxP34bdcKB8jYyIIP505GsY)



## Generating an invite link for your app

Next, generate an invite link for your application by picking the scopes and permissions it needs to function. To do this, go to **OAuth2** on the side menu, and in the dropdown menu, click on **URL Generator**. From the **SCOPES** section, select **bot**:

![](https://lh7-us.googleusercontent.com/3IWHSuw0Ru7p50hqknnZpvZ4F2QtiB_Dd6MZJ63n-OSkUcI9omuuSjAc-dA_TSX_EL192BPhRdrhArkJyec89AHrFbsBllUqtbJF0GXLiU5uwyyFWnrOULd8w0_LNPF1NIlBXpAeX2aGGBLikOEtSGA)


Under the **Bot Permissions** section, select **Administrator**:

![](https://lh7-us.googleusercontent.com/oMA_J80mgt6qbwWi5oT8YZYL12YhuLJN6m8Gc2bTeqKMCTS_JuH6BRqxUnNR6ZA06kKxPmU2XH-n-3fl-GmBN0Km20mySqV5UMcjc_rRrhdVMKHZGsAjupHCvrI3_mXNWKZ8SbslKqhTJ6zIGkb3KUg)


Once you select your scope and bot permissions, a URL will be generated. Scroll down to the bottom of the page and click the **Copy** button to copy your generated URL:

![](https://lh7-us.googleusercontent.com/87j5DbiHosJup__aZ2Qu8FOln-jIPeFFucBKUO_XsN-6P07jBi7PQrmYBG6pC4G_XUKJ7krDYX6DBTV8YoFIHhb6LPSzUDbg6Gz9RSMph_lDIG_IMGvWAerB70dL9R8-vtZrACTz1DnyjsxcgJmakJI)



## Adding your application to your Discord server

Go to your favorite browser and paste the URL in the search bar. This will open Discord with a message telling you that an external application wants to access your Discord account with information about what you are permitted to do, which includes adding a bot to a server and creating a command. Remember to have a server created and ready to go.

![](https://lh7-us.googleusercontent.com/o3dIuf5-_YP3N1TYvYsEEAM_GQtn73AhtoEseBU9ONg8lCPkmqKeUzjuckC9P0BL3S0_6-6ZgbE-SuiRQY-cse_7S8GIxeuuLHIFFadZtdgtXm6JkJvCA896Pj-9NjpiPgueTGlG5RwC76TxzePHNSI)


Select the server that you would like to add from your list of servers and click the **Continue** button:

![](https://lh7-us.googleusercontent.com/Egrl4rdDk5xf4h1LyambDao3WtbAkjrMN4slJXaSM3b8ZVFcJVgfOSvoe7sAy6RqsbDaEBX1OSB9RkvvhkE53U8Aby4sdTPGGKNKC6yiaAfy-IwmnTaCWDkladptW0cR4xNUEQWrhADSKqOQjvxcgPo)


Grant administrator permission to your server and click the **Authorize** button:

![](https://lh7-us.googleusercontent.com/JV1lu1lDG6Dd4v3FePm2V57FrxBtqGYV0243yV62xvrSAKErepvcftCp7v-h9107Ik68f-6sIdPICp5lPvEzoZiDJqOVvo4sbWQeHMW7uV-XtgXB_m3aupK97GVFOfgdF9SkSRGBfAyXNm4PLuH_CQY)


Once you do that, you’ll be required to confirm that you are not a robot:

![](https://lh7-us.googleusercontent.com/AynldEuQ9jYqf2TRZbn8S3ugYUTsSIWbJXW-hqxkzrfjiIR47y-OzKBYavbxPyt05aPCnG638UVio6nPA1JbHYt821wytJEQyMuvjPpCvb6q4dF--rv1zmFP98b8tGkIA_10p8o912oUOknUsZxn1C8)


Once you’ve been verified, your application will be successfully authorized and added to the server you created on Discord. Click on the **Go to Appwrite Bot Server** button to go to your server:

![](https://lh7-us.googleusercontent.com/HPdaCteh1kd8MLB1pZP8NLJtBiNmvGaR-xBmTqqLt9Sgc0yAKvizI6nV42cCsGNk77z5F1LLPYXndHosrgzEZkyTV47HhP-01H5_f-j51tb5FkSXx02an4RNkrNDOhF5qJMSO8Ry3WIAOTjzoDqlVw8)


This will take you to your server on Discord:

![](https://lh7-us.googleusercontent.com/hNkg3RJBHl8Db6fCVUjKoLQfgVX2pPzK-D6tm8b88pytf-AI3LZIclkRajQO2S6P43AnBcJzKhRLrPJPL1WuGyH2gfo-j13Uag6v8F8L27acJkHXiruYxdHQB_XT5EV0x4vjO-7kBUbXoPOmEaohggY)


Now, you can add commands to your Discord command bot using Appwrite functions.

## Customizing the template by adding Commands to your Discord command bot

With the Discord command template provided by Appwrite functions, you have access to a variety of customization options. You can do the following:


- Add, remove, or modify commands.
- Customize the responses of the Discord bot to commands.
- Set permissions for who can use the commands.
- Register the Discord bot to listen for and respond to Discord events, including reactions when a member leaves the Discord server or messages.

Not only do you have access to several customization options, but you also benefit from the speed that the Discord command bot template provides. For instance, instead of spending time developing the Discord bot from scratch, the Discord command bot template offers you a pre-built foundation with code that you can use to get started quickly. If you want to add more features to your discord bot, such as commands, you can easily customize the template by creating a new function and registering it with the Discord bot.

Let’s see this in action by customizing the template by adding a command to your Discord server that tells jokes.

In your Discord command bot GitHub repository, you have a **setup.js** file that registers the command on Discord by defining a name and description for the command. By default, the template already registers a “Hello World Command”. 

Here’s the link to the complete [source code](https://github.com/debemenitammy/discord-command-bot).

Let’s create another command by registering the command in the **setup.js** file. Modify the code in your **setup.js** file with the following:

```javascript
    import { fetch } from 'undici';
    import { throwIfMissing } from './utils.js';
    async function setup() {
      throwIfMissing(process.env, [
        'DISCORD_PUBLIC_KEY',
        'DISCORD_APPLICATION_ID',
        'DISCORD_TOKEN',
      ]);
      const registerApi = `https://discord.com/api/v9/applications/${process.env.DISCORD_APPLICATION_ID}/commands`;
      const commands = [
        {
          name: "hello",
          description: "Hello World Command"
        },
        {
          name: "jokes",
          description: "Tell a random joke"
        }
      ]
    
      const responses = await Promise.all(commands.map((command) => {
        return fetch(registerApi, {
          method: 'POST',
          headers: {
            Authorization: `Bot ${process.env.DISCORD_TOKEN}`,
            'Content-Type': 'application/json',
          },
          body: JSON.stringify(command),
        });
      }))
      if (responses.some((response) => !response.ok)) {
        throw new Error('Failed to register command');
      }
      console.log('Command registered successfully');
    }
    setup();
```

Here’s a detailed explanation of what this code does:

- The `throwIfMissing()` function checks if the environment variables that you set in your Appwrite function exist — here, this will include your **DISCORD_PUBLIC_KEY,** **DISCORD_APPLICATION_ID,** and **DISCORD_TOKEN**.
- The `registerApi` saves the URL to add the command to the Discord bot.
- The `commands` variable is an array of the commands you want to add to Discord.
- The `responses` variable stores the response from Discord after a request is made to register the command on your Discord server. If it fails, it throws an error; if it is successful, it logs a message to the console saying, “Command registered successfully.”

Next, go to the **main.js** file, which contains the code that handles the request to add a command to Discord and modify the code with the following:

```javascript

    import {
      InteractionResponseType,
      InteractionType,
      verifyKey,
    } from 'discord-interactions';
    import { throwIfMissing } from './utils.js';
    export default async ({ req, res, error, log }) => {
      throwIfMissing(process.env, [
        'DISCORD_PUBLIC_KEY',
        'DISCORD_APPLICATION_ID',
        'DISCORD_TOKEN',
      ]);
      if (
        !verifyKey(
          req.bodyRaw,
          req.headers['x-signature-ed25519'],
          req.headers['x-signature-timestamp'],
          process.env.DISCORD_PUBLIC_KEY
        )
      ) {
        error('Invalid request.');
        return res.json({ error: 'Invalid request signature' }, 401);
      }
      log('Valid request');
      const interaction = req.body;
      if (
        interaction.type === InteractionType.APPLICATION_COMMAND &&
        interaction.data.name === 'hello'
      ) {
        log('Matched hello command - returning message');
        return res.json(
          {
            type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
            data: {
              content: 'Hello, World!',
            },
          },
          200
        );
      }
       if (
        interaction.type === InteractionType.APPLICATION_COMMAND &&
        interaction.data.name === 'jokes'
      ) {
        log('Matched jokes command - returning message');
        const response = await fetch("https://v2.jokeapi.dev/joke/Any?type=twopart");
        const data = await response.json();
        return res.json(
          {
            type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
            data: {
              content: `${data.setup} ---------- ${data.delivery}`,
            },
          },
          200
        );
      }
      log("Didn't match command - returning PONG");
      return res.json({ type: InteractionResponseType.PONG }, 200);
    };
```

The code does the following:

- It verifies the data coming from the Discord server.
- It gets the name of the registered command, and it responds with the appropriate data. 

After customizing the template, commit your changes and push them to GitHub.

Once you commit and push your changes, your building process will start, and your code will be deployed on Appwrite. Go to your **Appwrite Functions** and click on the **Deployments** tab; you will see your build time and other information.

![](https://lh7-us.googleusercontent.com/wVuNmaZk3VV9pLxQJxQF3-NvlgjRxLcWXvuXzYXirs_8yV_m4jnvM0I1KA3K_Y0KqEjjBRcsMlqbMrZRE6P5w8PHZW51UOXwGL9iklj66nDu_i45p_X5K06apQ9HVoVRSuIPW3mMUo_apoi6-B2LvTY)


Scroll down on your **Deployments** tab to see the status of your deployment:

![](https://lh7-us.googleusercontent.com/7w8zKniHpigHqd_8XCX2kjhGY9iA_5YmGyuSqq6xrQtxo4e-h38c7t6s8IG2Vzdt_Rk7FPkTLwj6f5CzXGR1K7MXROpUahVq0u8OS_ci6ezSR-GzqCdFgO8TAExzBwC6HKGLmgJFCa_az0pRJ-WWzpk)


Finally, you can test this out to see if your command was successfully added to your Discord server by going to your discord server and typing “/jokes” as follows:

![](https://lh7-us.googleusercontent.com/xDRkPBLoE7dDJYYrQR9pEhPbGZMFRrOaOM9a65j4szeAvngYNcKp7pUrprQXYKKcliCnYzwLrsBl1Q-56vGxnmui6feeKOBxAUYWGlpynt1GQIyBHZYgDeV_DYme2GWJumERstZRK3KX7eYHjcWIHII)


You can see the description of your command that you set below your command name:

![](https://lh7-us.googleusercontent.com/yCU6eexn6CcnGfGDwPdhQ4iyH8slyAlxjS_FI4-Bjo8oj3zhrH9jV6ayJyJwjRsrRbSVafLZ-tPzwhUIGyglS5YSuFLxBi3-Q5xSdvxk-fcIzbJpweob-yhdqJkbzhE8vVgCaNcT6XzUqSuFuRIgrr8)


Once you hit enter, it starts sending your command to the Appwrite Function for execution and displays a response:

![](https://lh7-us.googleusercontent.com/40dR3DNZVTOncZThrw95_fsVE0QtwoHmDE4PGJx1HlXr-OYHFbq6I2qVdzf5EaCGYIB-rEk7qRCcfTxawhdwOQTT3JABZYLXfm6CcJCmnNjrzWXMZrNRvEHMF1yPvA1BT7bFRchtihAV1xcYKHNJwvU)

## Conclusion

This tutorial demonstrated the use of Appwrite Cloud Functions, which provides a Discord command bot template for building a Discord command bot. You learned how to customize the template and add commands to your Discord server.


## Resources

You may find the following resources useful:

- [How to Use Cloud Functions to Automate GitHub Moderation](https://dev.to/hackmamba/how-to-use-cloud-functions-to-automate-github-moderation-3g5p)
- [Keep Your Online Community Safe: Build Automated Message Moderation with Cloud Functions](https://dev.to/hackmamba/keep-your-online-community-safe-build-automated-message-moderation-with-appwrite-cloud-functions-23eg)





















 ****