How To Enable Text-to-Speech (TTS) on Your NodeJS Discord Bot

1. Log In to Your Panel


2. Select the ‘Files’ Tab

Cybrancee Panel in the files page, "Files" tab on the sidebar is highlighted

3. Create Your Main Bot’s File

Create a new file called index.js then paste the following code.

Cybrancee Panel, Create File dialog. Enter File Name (index.js)

What this code does:

  • Loads your bot token
  • Enables Intents, which Discord now requires
  • Creates a bot with the ! command prefix
  • Adds a !say command
    • When a user types !say, the bot replies with a TTS message
const { Client, IntentsBitField } = require('discord.js');

const TOKEN = 'YOUR_BOT_TOKEN';

const client = new Client({ 
    intents: [
        IntentsBitField.Flags.Guilds,
        IntentsBitField.Flags.GuildMessages,
        IntentsBitField.Flags.MessageContent,
    ] 
});

client.on('ready', () => {
    console.log(`Bot ready! Logged in as ${client.user.tag}`);
});

const PREFIX = '!';
client.on('messageCreate', async message => {
    if (message.author.bot || !message.content.startsWith(PREFIX)) return;

    const args = message.content.slice(PREFIX.length).trim().split(/ +/);
    const command = args.shift().toLowerCase();

    if (command === 'say') {
        await message.channel.send({ 
            content: 'Hello from your bot using T T S.', 
            tts: true 
        });
    }
});

client.login(TOKEN);

Discord Bot Hosting

Starts at $1.49

External link icon
Was this article helpful?
Please Share Your Feedback
How Can We Improve This Article?
Table of Contents