← Back to lessons
DISCORD SYSTEMS

Lesson — Tax Calculator System

Goal: Create a Roblox tax calculator slash command that takes an amount and returns the final price after tax.

Lesson Overview

In this lesson you will build a professional tax calculator command for your Discord bot. Users will run the /tax command and enter a number. The command will automatically calculate the Roblox taxed total and respond with a clean embed showing the result.

Video Lesson

Notes — Understanding the Code

SlashCommandBuilder

Creates the /tax slash command users can run in Discord.

addNumberOption()

Adds a required number input called amount so the user can enter the value they want to calculate tax for.

interaction.options.getNumber()

Retrieves the number entered by the user in the slash command.

Math.round(amount / 0.7)

Calculates the Roblox taxed amount by dividing by 0.7 and rounding the result. This gives the final price needed after Roblox takes its percentage.

EmbedBuilder

Creates a styled embed response so the tax result looks clean and professional inside Discord.

numberWithCommas()

Formats large numbers with commas so the output is easier to read. Example:
10000 → 10,000

interaction.reply()

Sends the finished embed back to the user after the calculation is complete.

setTimestamp()

Adds the current time to the embed for a polished final touch.

Step-by-Step

Create the command file

Create a new command file: commands/tax.js

This command will calculate Roblox tax and send the result in an embed.

Add the Tax Command

Show Code
const { SlashCommandBuilder, EmbedBuilder } = require('@discordjs/builders');
const { numberWithCommas } = require('../utils/numberWithCommas');

module.exports = {
	dev: false,
	cooldown: 2,
	defer: false,
	cache: true,

	data: new SlashCommandBuilder()
		.setName('tax')
		.setDescription('Roblox tax calculator.')
		.addNumberOption(option =>
			option
				.setName('amount')
				.setDescription('The amount to calculate tax for')
				.setRequired(true)
		),

	async execute(interaction) {
		const amount = interaction.options.getNumber('amount');
		const taxed = Math.round(amount / 0.7);

		const embed = new EmbedBuilder()
			.setTitle('Tax Calculator')
			.addFields(
				{
					name: 'Entered Amount',
					value: `**${numberWithCommas(amount)}**`,
					inline: true,
				},
				{
					name: 'Final Price (After Tax)',
					value: `**${numberWithCommas(taxed)}**`,
					inline: true,
				}
			)
			.setTimestamp();

		await interaction.reply({
			embeds: [embed],
		});
	},
};
Create the number formatting utility

Create: utils/numberWithCommas.js

This helper formats numbers nicely with commas before they are shown in the embed.

Add the Utility Code

Show Code
function numberWithCommas(x) {
  return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

module.exports = { numberWithCommas };

Restart the bot

node index.js

Your tax calculator command should now be working.

Challenge

Completion Checklist

← Course Home Next Lesson →