john.alite.
πŸ“Ž 1 file 1,217 chars
πŸ“„
pasted-code-1792866415264.txt
txt 19 lines
β–Ά
Create a complete Discord bot from scratch using JavaScript, Node.js, and discord.js v14.

I want a fully functional Discord Community and Marketplace bot with:

- Slash commands such as /setup, /help, /sell, /review and /controlpanel.
- Ticket system with buttons for Buy, Sell, Trade, Support, Report and Middleman.
- Marketplace listings with seller information, prices, descriptions and images.
- Review and vouch system for sellers.
- Moderation commands for ban, kick, timeout, warn and clear messages.
- Automatic moderation logs and deleted-message logs.
- Welcome messages and customizable embed messages.
- SQLite database to save listings, tickets and reviews.
- Admin-only commands and configurable staff roles.
- Professional black and purple embeds.
- A clean, organized JavaScript project with package.json and a README.
- Secure configuration using environment variables for the Discord bot token. Never expose the token in source code.
- Include complete code and clear instructions to install, configure and run the bot.

First create the actual Discord bot project and its JavaScript source files. Do not create a Chrome extension. Make the bot functional, not just a visual demo.
Kodari AI
KodariOct 24 at 6:29 pm 2
DiscordMarketHub
A comprehensive Discord community and marketplace bot built with Node.js and discord.js v14. Features slash commands for setup, help, selling, reviews, and an admin control panel. Implements a ticket system with Buy, Sell, Trade, Support, Report, and Middleman buttons. Includes marketplace listings with seller info, prices, descriptions, and images. Provides a review and vouch system, moderation commands for ban, kick, timeout, warn, and message clearing. Automatically logs moderation actions and deleted messages. Uses SQLite for persistent storage of listings, tickets, and reviews. Features admin-only commands, configurable staff roles, professional black and purple embeds, welcome messages, and customizable embed messages. Secure configuration via environment variables for the bot token.
  1. Add the bot entry point, slash-command handlers, persistent SQLite storage, and marketplace/ticket/moderation flows.

  2. Add dependency/config files and setup documentation, including required Discord intents and permissions.

Created the Discord.js v14 bot with slash commands, private ticket buttons, SQLite-backed listings/reviews/tickets/warnings, moderation tools, welcome messages, and logging. Setup instructions are in README.md; configure the token in .env using .env.example, then run npm install and npm start.

Enable Server Members Intent and Message Content Intent under your app’s Bot β†’ Privileged Gateway Intents in the Discord Developer Portal. The bot needs these for welcome messages and deleted-message content logs.

john.alite.

<redacted>

Kodari AI
KodariOct 24 at 6:38 pm 1

That looks like a Discord bot token, and it’s now exposed. Reset it immediately in the Discord Developer Portal under Your App β†’ Bot β†’ Reset Token; the old token will stop working.

Put the new token in your project’s .env file as DISCORD_TOKEN=... and restart the bot. Don’t post or commit the new token.

john.alite.

ok redy

Kodari AI
KodariOct 24 at 6:40 pm 1

Before starting, reset the token you posted and use the newly generated one in .env as DISCORD_TOKEN=.... Then run npm install and npm start.

Kodari can make mistakes. Review important code before using.
Files
src
.gitignore
package.json
README.md
Code
7 742
src/bot.js
require('dotenv').config();

const {
  ActionRowBuilder,
  ButtonBuilder,
  ButtonStyle,
  ChannelType,
  Client,
  Events,
  GatewayIntentBits,
  Partials,
  PermissionFlagsBits
} = require('discord.js');
const commands = require('./commands');
const database = require('./database');
const { clip, createEmbed } = require('./embeds');

if (!process.env.DISCORD_TOKEN) {
  throw new Error('DISCORD_TOKEN is missing. Add it to your .env file.');
}

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMembers,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent
  ],
  partials: [Partials.Message, Partials.Channel]
});

const ticketTypes = [
  { key: 'buy', label: 'Buy', emoji: 'πŸ›’' },
  { key: 'sell', label: 'Sell', emoji: 'πŸ’°' },
  { key: 'trade', label: 'Trade', emoji: 'πŸ”' },
  { key: 'support', label: 'Support', emoji: 'πŸ› οΈ' },
  { key: 'report', label: 'Report', emoji: '🚩' },
  { key: 'middleman', label: 'Middleman', emoji: '🀝' }
];

function hasManageServer(interaction) {
  return interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild)
    || interaction.memberPermissions?.has(PermissionFlagsBits.Administrator);
}

function hasStaffAccess(interaction) {
  if (hasManageServer(interaction)) return true;
  const roleId = database.getSetting(interaction.guildId, 'staff_role');
  if (!roleId) return false;
  const roles = interaction.member?.roles;
  return Array.isArray(roles) ? roles.includes(roleId) : Boolean(roles?.cache?.has(roleId));
}

async function deny(interaction, message = 'You do not have permission to use this command.') {
  await interaction.reply({ content: message, ephemeral: true });
}

async function logToGuild(guild, embed) {
  const channelId = database.getSetting(guild.id, 'logs_channel');
  if (!channelId) return;
  const channel = await guild.channels.fetch(channelId).catch(() => null);
  if (channel?.isTextBased()) {
    await channel.send({ embeds: [embed], allowedMentions: { parse: [] } }).catch(error => {
      console.error(`Could not send a log in guild ${guild.id}:`, error);
    });
  }
}

async function logAction(guild, title, fields) {
  const embed = createEmbed(title).addFields(fields);
  await logToGuild(guild, embed);
}

async function ensureTextChannel(guild, providedChannel, name, clientUserId, staffRoleId, privateChannel = false) {
  if (providedChannel) return providedChannel;
  const permissionOverwrites = privateChannel
    ? [
        { id: guild.id, deny: [PermissionFlagsBits.ViewChannel] },
        { id: clientUserId, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.EmbedLinks, PermissionFlagsBits.ReadMessageHistory] },
        ...(staffRoleId ? [{ id: staffRoleId, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.ReadMessageHistory] }] : [])
      ]
    : undefined;
  return guild.channels.create({
    name,
    type: ChannelType.GuildText,
    permissionOverwrites
  });
}

async function handleSetup(interaction) {
  if (!hasManageServer(interaction)) return deny(interaction, 'Only members with Manage Server or Administrator can configure the bot.');
  await interaction.deferReply({ ephemeral: true });

  const guild = interaction.guild;
  const staffRole = interaction.options.getRole('staff_role');
  const logs = await ensureTextChannel(guild, interaction.options.getChannel('logs_channel'), 'bot-logs', client.user.id, staffRole?.id, true);
  const listings = await ensureTextChannel(guild, interaction.options.getChannel('listings_channel'), 'marketplace', client.user.id, staffRole?.id);
  const welcome = await ensureTextChannel(guild, interaction.options.getChannel('welcome_channel'), 'welcome', client.user.id, staffRole?.id);
  let ticketCategory = interaction.options.getChannel('ticket_category');
  if (!ticketCategory) {
    ticketCategory = await guild.channels.create({ name: 'Tickets', type: ChannelType.GuildCategory });
  }

  database.setSetting(guild.id, 'logs_channel', logs.id);
  database.setSetting(guild.id, 'listings_channel', listings.id);
  database.setSetting(guild.id, 'welcome_channel', welcome.id);
  database.setSetting(guild.id, 'ticket_category', ticketCategory.id);
  if (staffRole) database.setSetting(guild.id, 'staff_role', staffRole.id);
  const welcomeMessage = interaction.options.getString('welcome_message');
  if (welcomeMessage) database.setSetting(guild.id, 'welcome_message', welcomeMessage);
  else if (!database.getSetting(guild.id, 'welcome_message')) {
    database.setSetting(guild.id, 'welcome_message', 'Welcome {user} to **{server}**!');
  }

  await interaction.editReply(
    `Setup complete. Logs: <#${logs.id}> β€’ Marketplace: <#${listings.id}> β€’ Welcome: <#${welcome.id}> β€’ Tickets: **${ticketCategory.name}**${staffRole ? ` β€’ Staff: <@&${staffRole.id}>` : ''}`
  );
}

async function handleSell(interaction) {
  const imageUrl = interaction.options.getString('image');
  if (imageUrl) {
    try {
      const parsed = new URL(imageUrl);
      if (!['http:', 'https:'].includes(parsed.protocol)) throw new Error('Unsupported protocol');
    } catch {
      return deny(interaction, 'The image must be a valid public HTTP or HTTPS URL.');
    }
  }

  const channelId = database.getSetting(interaction.guildId, 'listings_channel');
  const channel = channelId ? await interaction.guild.channels.fetch(channelId).catch(() => null) : null;
  if (!channel?.isTextBased()) return deny(interaction, 'The marketplace is not configured yet. Ask a server manager to run `/setup`.');

  await interaction.deferReply({ ephemeral: true });
  const listing = {
    guildId: interaction.guildId,
    sellerId: interaction.user.id,
    title: interaction.options.getString('title'),
    price: interaction.options.getString('price'),
    description: interaction.options.getString('description'),
    imageUrl
  };
  const listingId = database.createListing(listing);
  const embed = createEmbed(listing.title, listing.description)
    .setAuthor({ name: `${interaction.user.tag} β€’ Seller`, iconURL: interaction.user.displayAvatarURL() })
    .addFields(
      { name: 'Price', value: clip(listing.price, 50), inline: true },
      { name: 'Seller', value: `<@${interaction.user.id}>`, inline: true }
    )
    .setFooter({ text: `Listing #${listingId}` });
  if (imageUrl) embed.setImage(imageUrl);

  const posted = await channel.send({ embeds: [embed], allowedMentions: { users: [interaction.user.id] } });
  await interaction.editReply(`Your listing was posted: https://discord.com/channels/${interaction.guildId}/${channel.id}/${posted.id}`);
}

async function handleReview(interaction) {
  const seller = interaction.options.getUser('seller');
  if (seller.id === interaction.user.id) return deny(interaction, 'You cannot review yourself.');

  const review = {
    guildId: interaction.guildId,
    reviewerId: interaction.user.id,
    sellerId: seller.id,
    rating: interaction.options.getInteger('rating'),
    comment: interaction.options.getString('comment')
  };
  let reviewId;
  try {
    reviewId = database.createReview(review);
  } catch (error) {
    if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {
      return deny(interaction, 'You have already reviewed this seller in this server.');
    }
    throw error;
  }

  const channelId = database.getSetting(interaction.guildId, 'listings_channel');
  const channel = channelId ? await interaction.guild.channels.fetch(channelId).catch(() => null) : null;
  if (channel?.isTextBased()) {
    const embed = createEmbed('Seller review', review.comment)
      .addFields(
        { name: 'Seller', value: `<@${seller.id}>`, inline: true },
        { name: 'Rating', value: `${'⭐'.repeat(review.rating)} (${review.rating}/5)`, inline: true },
        { name: 'Reviewer', value: `<@${interaction.user.id}>`, inline: true }
      )
      .setFooter({ text: `Review #${reviewId}` });
    await channel.send({ embeds: [embed], allowedMentions: { users: [seller.id, interaction.user.id] } });
  }
  await interaction.reply({
    content: channel?.isTextBased() ? 'Your review was saved and posted.' : 'Your review was saved. A server manager can configure its display channel with `/setup`.',
    ephemeral: true
  });
}

function makeTicketPanel() {
  const embed = createEmbed('Community support', 'Choose the button that best matches your request. A private channel will be created for you and the staff team.');
  const rows = [
    new ActionRowBuilder().addComponents(ticketTypes.slice(0, 5).map(type =>