Untitled

 avatar
unknown
plain_text
2 years ago
2.9 kB
3
Indexable
const fs = require('fs');
const { Client, GatewayIntentBits, MessageEmbed, REST } = require('discord.js');
const { Routes } = require('discord-api-types/v9');

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.GuildMessageContent,
    GatewayIntentBits.DirectMessages,
    GatewayIntentBits.DirectMessageContent
  ]
});

const rest = new REST({ version: '9' }).setToken('TOKEN_DO_SEU_BOT');
const clientId = 'ID_DO_SEU_CLIENTE';
const guildId = 'ID_DO_SEU_SERVIDOR';

client.once('ready', () => {
  console.log(`Bot conectado como ${client.user.tag}`);
});

client.on('interactionCreate', async (interaction) => {
  if (!interaction.isCommand()) return;

  const { commandName, options } = interaction;

  if (commandName === 'seu-comando-slash') {
    const data = JSON.parse(fs.readFileSync('data.json'));
    const orderId = data.lastOrderId + 1;

    data.lastOrderId = orderId;
    fs.writeFileSync('data.json', JSON.stringify(data, null, 2));

    const comprador = options.getString('comprador');
    const subTier = options.getString('subtier');
    const streamer = options.getUser('streamer');

    const attachment = interaction.attachments.first();
    if (!attachment || !attachment.isImage()) {
      return interaction.reply('Por favor, envie uma imagem válida.');
    }

    const channel = client.channels.cache.get('ID_DO_CANAL');

    const embed = new MessageEmbed()
      .setColor('#0099ff')
      .setTitle('Informações do Comprador')
      .addFields(
        { name: 'Order ID', value: orderId.toString() },
        { name: 'Comprador', value: `<@${comprador}>` },
        { name: 'Sub Tier', value: subTier },
        { name: 'Streamer', value: `<@${streamer.id}>` }
      )
      .setImage(attachment.url);

    await channel.send({ embeds: [embed] });
    interaction.reply('Informações enviadas com sucesso!');
  }
});

(async () => {
  try {
    await rest.put(
      Routes.applicationGuildCommands(clientId, guildId),
      { body: [
        {
          name: 'seu-comando-slash',
          description: 'Descrição do seu comando',
          options: [
            {
              type: 'STRING',
              name: 'comprador',
              description: 'Descrição do comprador',
              required: true
            },
            {
              type: 'STRING',
              name: 'subtier',
              description: 'Descrição do sub tier',
              required: true
            },
            {
              type: 'USER',
              name: 'streamer',
              description: 'Descrição do streamer',
              required: true
            }
          ]
        }
      ]}
    );

    console.log('Comandos slash registrados com sucesso!');
  } catch (error) {
    console.error(error);
  }
})();

client.login('TOKEN_DO_SEU_BOT');
Editor is loading...