Say Command

Simple tutorial for making the bot say specific messages.

In this tutorial, we will be making a simple command that says a specific message, as the bot. Say for example you want the bot to say "Hello". We can input this into our interaction.reply() function and make the bot say whatever.

To get started, we need to create a command with the following structure:

const { SlashCommandBuilder } = require("discord.js");

module.exports = {
  data: new SlashCommandBuilder()
  .setName('say')
  .setDescription('Say a message, as the bot')
  .addStringOption(option => (
    option,
    .setName('message')
    .setDescription('The message to say')
    .setRequired(true)
  )),
  run: async ({ client, interaction }) => {},
};

This structure will define our Slash Command, along with its needed option for our input. This input is marked as a "String Input" which will take a list of characters.

For example: "Hello, World" is considered a string, and so is anything in double quotes "" single quotes '' or "back-ticks" ``.

Now that we have defined our command structure, we need to handle the events for running the bot, so we will add the following line to fetch the value of our message option:

const message = interaction.options.getString("message");

Now that we have this saved in our file, it should look similar to

const { SlashCommandBuilder } = require("discord.js");

module.exports = {
  data: new SlashCommandBuilder()
  .setName('say')
  .setDescription('Say a message, as the bot')
  .addStringOption(option => (
    option,
    .setName('message')
    .setDescription('The message to say')
    .setRequired(true)
  )),
  run: async ({ client, interaction }) => {
    const message = interaction.options.getString("message");

  },
};

Finally, there are two ways we can make this command. This is because of how Slash Commands work.

Continuing this tutorial, it will show how to do it in part ONE. In this step, the command WILL SHOW THE AUTHOR of the command, but part TWO will make this invisible.

Say Command - PT2

Continuing with part ONE, we are pretty much done with our command, so we finish off by replying to the interaction with our messagevariable.

const { SlashCommandBuilder } = require("discord.js");

module.exports = {
  data: new SlashCommandBuilder()
  .setName('say')
  .setDescription('Say a message, as the bot')
  .addStringOption(option => (
    option,
    .setName('message')
    .setDescription('The message to say')
    .setRequired(true)
  )),
  run: async ({ client, interaction }) => {
    const message = interaction.options.getString("message");

    interaction.reply(message);
  },
};

And this concludes part ONE. After restarting Discord to register the command on the client side, it should appear as /say <message> and if you input a message, the bot will response with it.

Last updated