To implement these slash commands for your Discord bot using Discord.js v14, you will need to create separate files for each command. Here's a basic structure for how each command file could look:
1. calculate.js
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('calculate')
.setDescription('Calculates the given evaluation')
.addStringOption(option =>
option.setName('evaluation')
.setDescription('The mathematical expression to evaluate')
.setRequired(true)),
async execute(interaction) {
const eval = interaction.options.getString('evaluation');
try {
const result = eval(eval);
await interaction.reply(`Result: ${result}`);
} catch (error) {
await interaction.reply('Error in calculation. Please check your expression.');
}
},
};
2. server.js
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('server')
.setDescription('Shows information about server'),
async execute(interaction) {
await interaction.reply(`Server name: ${interaction.guild.name}\nTotal members: ${interaction.guild.memberCount}`);
},
};
3. about.js
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('about')
.setDescription('Shows information about bot'),
async execute(interaction) {
await interaction.reply('This is a Discord bot made with Discord.js!');
},
};
4. help.js
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Shows information about command')
.addStringOption(option =>
option.setName('command')
.setDescription('The command to get help with')
.setRequired(false)),
async execute(interaction) {
const command = interaction.options.getString('command');
if (command) {
await interaction.reply(`Help for command: ${command}`);
} else {
await interaction.reply('Listing all available commands...');
}
},
};
5. emoji.js
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('emoji')
.setDescription('Shows information about emoji and displays it in full resolution')
.addStringOption(option =>
option.setName('emoji')
.setDescription('The emoji to display')
.setRequired(true)),
async execute(interaction) {
const emoji = interaction.options.getString('emoji');
await interaction.reply(`Emoji: ${emoji}`);
},
};
6. whois.js
const { SlashCommandBuilder } = require('@discordjs/builders');
const whois = require('whois-json');
module.exports = {
data: new SlashCommandBuilder()
.setName('whois')
.setDescription('Shows information about given site')
.addStringOption(option =>
option.setName('url')
.setDescription('The URL of the site')
.setRequired(true)),
async execute(interaction) {
const url = interaction.options.getString('url');
try {
const data = await whois(url);
await interaction.reply(`Whois information for ${url}: ${JSON.stringify(data)}`);
} catch (error) {
await interaction.reply('Failed to fetch Whois data.');
}
},
};
7. 2ip.js
const { SlashCommandBuilder } = require('@discordjs/builders');
const fetch = require('node-fetch');
module.exports = {
data: new SlashCommandBuilder()
.setName('2ip')
.setDescription('Shows information about given IP')
.addStringOption(option =>
option.setName('ip')
.setDescription('The IP address to lookup')
.setRequired(true)),
async execute(interaction) {
const ip = interaction.options.getString('ip');
try {
const response = await fetch(`https://ipinfo.io/${ip}/json`);
const data = await response.json();
await interaction.reply(`IP info for ${ip}: ${JSON.stringify(data)}`);
} catch (error) {
await interaction.reply('Failed to fetch IP information.');
}
},
};
8. convert.js
You should use an external API like exchangeratesapi.io for currency conversion, but here's a simplified version without actual API integration:
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('convert')
.setDescription('Converts the given amount from currency 1 to currency 2')
.addStringOption(option =>
option.setName('currency1')
.setDescription('The source currency')
.setRequired(true))
.addNumberOption(option =>
option.setName('amount')
.setDescription('Amount to convert')
.setRequired(true))
.addStringOption(option =>
option.setName('currency2')
.setDescription('The target currency')
.setRequired(true)),
async execute(interaction) {
const currency1 = interaction.options.getString('currency1');
const amount = interaction.options.getNumber('amount');
const currency2 = interaction.options.getString('currency2');
// Dummy conversion rate
const rate = 1.2;
const convertedAmount = amount * rate;
await interaction.reply(`${amount} ${currency1} is approximately ${convertedAmount} ${currency2} at a rate of ${rate}.`);
},
};
9. avatar.js
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('avatar')
.setDescription("Shows user's avatar"),
async execute(interaction) {
const user = interaction.user;
await interaction.reply(`${user.username}'s avatar: ${user.displayAvatarURL({ dynamic: true })}`);
},
};
10. banner.js
Note: Discord.js v14 does not directly provide user banners. You may require additional API requests via discord-api-types.
11. stocks.js
For this, you would use a financial API to fetch stock data. Here’s a placeholder:
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('stocks')
.setDescription('Shows information about stocks by symbol and time')
.addStringOption(option =>
option.setName('symbol')
.setDescription('The stock symbol to search for')
.setRequired(true))
.addStringOption(option =>
option.setName('time')
.setDescription('Time period for the stock data')
.addChoices(
{ name: '1 Day', value: '1day' },
{ name: '1 Month', value: '1month' },
{ name: '6 Months', value: '6months' },
{ name: '1 Year', value: '1year' },
{ name: '10 Years', value: '10years' },
{ name: 'All', value: 'all' })
.setRequired(true)),
async execute(interaction) {
const symbol = interaction.options.getString('symbol');
const time = interaction.options.getString('time');
// Placeholder response
await interaction.reply(`Fetching stock data for ${symbol} over ${time}...`);
},
};
12. encrypt-aes.js
You’d use a library like crypto or crypto-js for AES encryption.
const { SlashCommandBuilder } = require('@discordjs/builders');
const crypto = require('crypto');
function encrypt(text, key) {
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv); // iv is initialization vector
let encrypted = cipher.update(text, 'utf8', 'hex');
encrypted += cipher.final('hex');
return encrypted;
}
module.exports = {
data: new SlashCommandBuilder()
.setName('encrypt-aes')
.setDescription('Encrypts given text using given key')
.addStringOption(option =>
option.setName('text')
.setDescription('Text to encrypt')
.setRequired(true))
.addIntegerOption(option =>
option.setName('keybits')
.setDescription('Key size in bits')
.addChoices(
{ name: '128', value: 128 },
{ name: '192', value: 192 },
{ name: '256', value: 256 })
.setRequired(true))
.addStringOption(option =>
option.setName('key')
.setDescription('The encryption key')
.setRequired(true)),
async execute(interaction) {
const text = interaction.options.getString('text');
const keybits = interaction.options.getInteger('keybits');
const key = interaction.options.getString('key');
// Note: This example lacks proper input handling for keys and IV generation
const encrypted = encrypt(text, key);
await interaction.reply(`Encrypted text: ${encrypted}`);
},
};
13. decrypt-aes.js
const { SlashCommandBuilder } = require('@discordjs/builders');
const crypto = require('crypto');
function decrypt(encrypted, key) {
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); // iv is initialization vector
let decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
module.exports = {
data: new SlashCommandBuilder()
.setName('decrypt-aes')
.setDescription('Decrypts given text using given key')
.addStringOption(option =>
option.setName('text')
.setDescription('Text to decrypt')
.setRequired(true))
.addStringOption(option =>
option.setName('key')
.setDescription('The decryption key')
.setRequired(true)),
async execute(interaction) {
const encryptedText = interaction.options.getString('text');
const key = interaction.options.getString('key');
// Note: This example lacks proper input handling for keys and IV generation
const decrypted = decrypt(encryptedText, key);
await interaction.reply(`Decrypted text: ${decrypted}`);
},
};
Setting Up Commands
Make sure to include all these command files in your command handler, where they can be added to your client and deployed as necessary. You will need to modify directory paths and handling as per your project's structure.