const {SlashCommandBuilder, ActionRowBuilder, Events,
ModalBuilder, TextInputBuilder, TextInputStyle, Client, GatewayIntentBits,
ButtonBuilder, ButtonStyle, EmbedBuilder, MessageButton } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessageReactions,] });
const { Sequelize, Model, DataTypes } = require("sequelize");
const mineflayer = require('mineflayer');
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect: 'sqlite',
logging: false,
// SQLite
storage: 'database.sqlite',
});
const botsDATA = sequelize.define('botsDATA', {
ИмяБота: {
type: Sequelize.STRING,
primaryKey: true
},
IDгильдии: {
type: Sequelize.INTEGER,
},
ВремяПодписки: Sequelize.INTEGER,
});
module.exports = {
data: new SlashCommandBuilder()
.setName('старт')
.setDescription('Запустить бота')
.addStringOption(option => option.setName('ip').setDescription('Айпи сервера').setRequired(true))
.addIntegerOption(option => option.setName('порт').setDescription('Порт сервера')),
async execute(interaction) {
//начало кода
const guildID = interaction.guild.id
const port1 = interaction.options.getInteger('порт');
const host1 = interaction.options.getString('ip');
const project = await botsDATA.findOne({ where: { IDгильдии: guildID } });
if (project === null) {
const modal = new ModalBuilder()
.setCustomId('BUYmodal')
.setTitle('Купить бота')
.addComponents([
new ActionRowBuilder().addComponents(
new TextInputBuilder()
.setCustomId('BotName-input')
.setLabel('Никнейм Бота')
.setStyle(TextInputStyle.Short)
.setMinLength(3)
.setMaxLength(16)
.setPlaceholder('HS_bot')
.setRequired(true),
),
]);
await interaction.showModal(modal);
interaction.awaitModalSubmit({ time: 99999_000})
.then(
interaction => interaction.reply(`HSbot_${interaction.fields.getTextInputValue('BotName-input')} будет активен дней!`)
)
.catch(err => console.log('No modal submit interaction was collected'));
} else {
const msg = await interaction.reply("Подключение...");
const BotName = project.ИмяБота
const bot = mineflayer.createBot({
host: host1,
port: port1,
version: false,
username: BotName,
});
bot.once('login', () => {
unm = bot.username
const embed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle('Подключено')
// .setURL('')
.setDescription(`${unm} успешно присоединился к серверу "${host1}"!`);
msg.edit({
content: ``,
embeds: [embed],
components: [
new ActionRowBuilder()
.addComponents([
new ButtonBuilder()
.setCustomId('Капча')
.setLabel('Капча')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('Выйти')
.setLabel('Выйти')
.setStyle(ButtonStyle.Danger)
]),
]
});
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isButton()) return;
console.log("test")
interaction.reply({
content: 'test',
ephemeral: true,
});
}
)
})
}
}
}
//конец кода