Discord Bot

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import { Client, Intents, MessageEmbed } from 'discord.

js';

const coin_name = "StarCoins"; // Set the name of your custom currency here
const coin_emoji = "<:StarCoin2:1093533634885062718>"; // Set your coin emoji here

const client = new Client({ intents: [Intents.FLAGS.GUILDS,


Intents.FLAGS.GUILD_MESSAGES] });

const coins = {}; // Define a dictionary to keep track of users' coins

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

client.on('messageCreate', async (message) => {


if (message.author.bot) {
return; // Ignore messages from other bots
}

if (!coins[message.author.id]) {
coins[message.author.id] = 0; // Initialize coins for user if not already set
}

coins[message.author.id]++; // Increment user's message count for each message


});

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


if (!interaction.isCommand()) {
return; // Ignore non-command interactions
}

switch (interaction.commandName) {
case 'balance':
if (!coins[interaction.user.id]) {
coins[interaction.user.id] = 0; // Initialize coins for user if not already set
}

const coin_balance = coins[interaction.user.id];


const balance_embed = new MessageEmbed()
.setColor('YELLOW')
.setTitle(`${interaction.user.username}'s Balance`)
.setTimestamp()
.setDescription(`${coin_balance} ${coin_name} ${coin_emoji}`);
await interaction.reply({ embeds: [balance_embed] });
break;
case 'buy':
const buy_embed = new MessageEmbed()
.setColor('GREEN')
.setTitle('Buy')
.setTimestamp()
.setDescription(`Enter the ID of the item you wish to purchase`);
await interaction.reply({ embeds: [buy_embed] });
break;
case 'shop':
const shop_embed = new MessageEmbed()
.setColor('BLUE')
.setTitle('Shop')
.setTimestamp()
.setDescription(`A Shop for all your needs!`);
await interaction.reply({ embeds: [shop_embed] });
break;
case 'inventory':
if (!coins[interaction.user.id]) {
coins[interaction.user.id] = 0;
}
const inventory_embed = new MessageEmbed()
.setColor('BLUE')
.setThumbnail(interaction.user.displayAvatarURL())
.setTitle(`${interaction.user.username}'s Inventory`)
.setTimestamp();
await interaction.reply({ embeds: [inventory_embed] });
break;
case 'help':
const help_embed = new MessageEmbed()
.setColor('RANDOM')
.setTitle('Commands')
.setTimestamp()
.addFields(
{
name: '🏦 Balance',
value: 'Check your balance'
},
{
name: '🛒 Shop',
value: 'View available items for purchase'
},
{
name: '🛍️ Buy',
value: 'Buy something from the shop!'
},
{
name: '🎁 Give',
value: 'Sharing is Caring!, Share your coins with others'
},
{
name: '📦 Inventory',
value: 'View all your available items'
},
{
name: '📙 Help',
value: 'View available commands'
}
);
await interaction.reply({ embeds: [help_embed] });
break;
default:
await interaction.reply('Unknown command.');
}
});

client.login("MTA5MDIwNzM2OTgwNTQzMDg5NA.GKadLT.BCLer8gyvsl34ElLw4KZ8b1vHKXReeuiFuB
pL8");

You might also like