0% found this document useful (0 votes)
6 views2 pages

Code

This document is a Discord bot implementation using Node.js that allows users to place and view orders through slash commands. It defines two commands: '/order' for posting order confirmations and '/todayorders' for listing all orders placed on the current day. The bot stores orders in memory and resets the order list at midnight.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Code

This document is a Discord bot implementation using Node.js that allows users to place and view orders through slash commands. It defines two commands: '/order' for posting order confirmations and '/todayorders' for listing all orders placed on the current day. The bot stores orders in memory and resets the order list at midnight.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

require('dotenv').

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

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

// Store image link (upload to Discord and replace this link)


const STORE_IMAGE =
'https://cdn.discordapp.com/attachments/1404643138060156958/1404759642906693662/
now_make_logo_in_wid.png?
ex=689c5bde&is=689b0a5e&hm=acb4b34da2914c51b55d71fd06b46219f12b8c81642476e64f30d84f
e5600392&';

// Store orders in memory


let dailyOrders = [];

// Slash commands
const commands = [
new SlashCommandBuilder()
.setName('order')
.setDescription('Post an order confirmation embed')
.addStringOption(option =>
option.setName('buyer').setDescription('Buyer name or
mention').setRequired(true))
.addStringOption(option =>
option.setName('product').setDescription('Product name').setRequired(true))
.addIntegerOption(option =>
option.setName('order_no').setDescription('Order number').setRequired(true))
.addIntegerOption(option =>
option.setName('quantity').setDescription('Quantity').setRequired(true))
.toJSON(),

new SlashCommandBuilder()
.setName('todayorders')
.setDescription('List all orders placed today')
.toJSON()
];

async function registerCommands() {


const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{ body: commands }
);
console.log('✅ Slash commands registered.');
}

client.once('ready', () => {
console.log(`🤖 Logged in as ${client.user.tag}`);
registerCommands();
});

client.on('interactionCreate', async interaction => {


if (!interaction.isCommand()) return;

// Handle /order
if (interaction.commandName === 'order') {
const buyer = interaction.options.getString('buyer');
const product = interaction.options.getString('product');
const orderNo = interaction.options.getInteger('order_no');
const quantity = interaction.options.getInteger('quantity');

// Save order in memory


dailyOrders.push({ buyer, product, orderNo, quantity, time: new Date() });

const embed = new EmbedBuilder()


.setColor(0xFF8C00)
.setTitle('✅ Order Confirmed')
.setDescription(`**Order No:** \`${orderNo}\``)
.addFields(
{ name: 'Product', value: product, inline: true },
{ name: 'Quantity', value: `${quantity}x`, inline: true },
{ name: 'Buyer', value: buyer, inline: false }
)
.setThumbnail(STORE_IMAGE)
.setImage(STORE_IMAGE)
.setFooter({ text: 'Legit Store by Rattys', iconURL: STORE_IMAGE })
.setTimestamp();

await interaction.reply({ embeds: [embed] });


}

// Handle /todayorders
if (interaction.commandName === 'todayorders') {
if (dailyOrders.length === 0) {
return interaction.reply({ content: '📭 No orders today.', ephemeral: true });
}

// Format orders
const orderList = dailyOrders.map(o =>
`#${o.orderNo} | ${o.product} (${o.quantity}x) - Buyer: ${o.buyer} - $
{o.time.toLocaleTimeString()}`
).join('\n');

const embed = new EmbedBuilder()


.setColor(0xFF8C00)
.setTitle('📦 Today\'s Orders')
.setDescription(orderList)
.setFooter({ text: 'Legit Store by Rattys', iconURL: STORE_IMAGE })
.setTimestamp();

await interaction.reply({ embeds: [embed] });


}
});

// Reset orders at midnight


setInterval(() => {
const now = new Date();
if (now.getHours() === 0 && now.getMinutes() === 0) {
dailyOrders = [];
console.log('🕛 Orders reset for the new day.');
}
}, 60000);

client.login(process.env.BOT_TOKEN);

You might also like