Goal: Create a Roblox tax calculator slash command that takes an amount and returns the final price after tax.
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.
Creates the /tax slash command users can run in Discord.
Adds a required number input called amount so the user can enter the value they want to calculate tax for.
Retrieves the number entered by the user in the slash command.
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.
Creates a styled embed response so the tax result looks clean and professional inside Discord.
Formats large numbers with commas so the output is easier to read.
Example:
10000 → 10,000
Sends the finished embed back to the user after the calculation is complete.
Adds the current time to the embed for a polished final touch.
Create a new command file:
commands/tax.js
This command will calculate Roblox tax and send the result in an embed.
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:
utils/numberWithCommas.js
This helper formats numbers nicely with commas before they are shown in the embed.
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
module.exports = { numberWithCommas };
node index.js
Your tax calculator command should now be working.
/tax command appears in Discord