liam123457.3

Hello I want a dsicord bot that has commands /say and that only

Kodari AI
KodariSep 26 at 9:13 am 1
DiscordSayBot
A Discord bot with a single slash command /say that allows users to send messages through the bot. The bot listens for the /say command, captures the user's input text, and reposts it as a bot message in the same channel. Built with JavaScript using Discord.js library, featuring a simple command handler, message formatting, and error handling for empty or invalid inputs. The bot connects to Discord via a bot token and responds instantly to commands.
  1. Create a minimal discord.js bot with /say as its only command.

  2. Register the slash command on startup and read credentials from environment variables.

  3. Prevent /say from triggering user or role mentions.

Created a Discord bot with /say as its only command. It won’t trigger user or role mentions.

Copy .env.example to .env, add your bot token and application ID, then run npm install and npm start. Invite the bot with the bot and applications.commands scopes.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
index.js
package.json
Code
3 80
index.js
require('dotenv').config();

const {
  Client,
  Events,
  GatewayIntentBits,
  REST,
  Routes,
  SlashCommandBuilder
} = require('discord.js');

const { DISCORD_TOKEN, CLIENT_ID } = process.env;

if (!DISCORD_TOKEN || !CLIENT_ID) {
  throw new Error('Set DISCORD_TOKEN and CLIENT_ID in your .env file.');
}

const commands = [
  new SlashCommandBuilder()
    .setName('say')
    .setDescription('Make the bot say something.')
    .addStringOption(option =>
      option
        .setName('message')
        .setDescription('What the bot should say')
        .setRequired(true)
    )
    .toJSON()
];

const client = new Client({
  intents: [GatewayIntentBits.Guilds]
});

client.once(Events.ClientReady, async readyClient => {
  try {
    const rest = new REST({ version: '10' }).setToken(DISCORD_TOKEN);
    await rest.put(Routes.applicationCommands(CLIENT_ID), { body: commands });
    console.log(`Ready as ${readyClient.user.tag}; /say is registered.`);
  } catch (error) {
    console.error('Failed to register /say:', error);
  }
});

client.on(Events.InteractionCreate, async interaction => {
  if (!interaction.isChatInputCommand() || interaction.commandName !== 'say') {
    return;
  }

  const message = interaction.options.getString('message', true);
  await interaction.reply({
    content: message,
    allowedMentions: { parse: [] }
  });
});

client.on(Events.Error, error => {
  console.error('Discord client error:', error);
});

client.login(DISCORD_TOKEN).catch(error => {
  console.error('Failed to log in to Discord:', error);
  process.exitCode = 1;
});